Forum guidelines
  • Home
  • »
  • C# Language
  • »
  • how to display string 'nani' the first letter as Capital 'N'
AuthorQuestion
how to display string 'nani' the first letter as Capital 'N'
Posted By nani nani on 12 Feb 2008

Hello,

          I appreciate if any one can give me C# code to display the string 'nani' into 'Nani'


Cheers,
Nani
AuthorReply
Alan
  • 0
  • 0
Re: how to display string 'nani' the first letter as Capital 'N'
Posted By Alan on 12 Feb 2008  

A couple of possible ways both of which would also convert stuff like 'nAni' and 'naNi' to 'Nani':

using System;
using System.Threading;
using System.Globalization;

class Test
{
     static void Main()
     {

       string nani = "nani";

       // first way
       string Nani = nani.ToLower();
       char first = Char.ToUpper(Nani[0]); 
       Nani = first + Nani.Substring(1);
       Console.WriteLine(Nani);
 
       // second way
       TextInfo ti = Thread.CurrentThread.CurrentCulture.TextInfo;   
       string Nani2 = ti.ToTitleCase(nani);
       Console.WriteLine(Nani2);
 
       Console.ReadLine();
     }

}

 


Download Free E-books

SPONSORED BY

Spire.Doc - Free .NET Word API
Use Spire.Doc to create, read, write, print, and convert word documents to OpenXML, RTF, TXT, XPS, EPUB, EMF, HTML, Image and PDF.