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

}

 


Employers - Post Free Jobs

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.