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();
     }

}

 


Infragistics jQuery Controls

SPONSORED BY

JetBrains ReSharper Ultimate
.NET code analysis, refactorings, navigation, unit testing, code coverage and profiling in Visual Studio, a bonus for C++ devs, bundled at 50% off.