2

I'm attempting to return a username in ASP.net but would prefer to convert the first character to upper, for example if a username is 'test' I would want to return 'Test'.

Code to get username:

<h3>Welcome Home<strong><%: User.Identity.Name %></strong>.

Not 100% sure on how to implement this and I'm pretty sure it will just end up being something simple but any help would be appreciated.

Thanks

FIXED

h3>Welcome Home <strong><%: User.Identity.Name.ToUpper().Substring(0,1) + User.Identity.Name.ToLower().Substring(1) %></strong>.
JayH
  • 194
  • 1
  • 3
  • 17
  • 2
    @sarwar026 This is not a duplicate of that one. This one doesn't ask about having the rest of the string converted to lowercase. –  Jul 04 '13 at 14:06
  • same question here : http://stackoverflow.com/questions/4135317/make-first-letter-of-each-word-upper-case – Gilles V. Jul 04 '13 at 14:06
  • @rightfold not sure if serious... If the linked question contained "How to make first character uppercase and rest lowercase", OP could be helped by just reading the first sentence of the accepter answer. This question is not unique enough. – CodeCaster Jul 04 '13 at 14:28

4 Answers4

9
System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(User.Identity.Name);    
Riv
  • 1,849
  • 1
  • 16
  • 16
3

You can achive that with the following example

string input;

char.ToUpper(input[0]) + input.Substring(1);
Droxx
  • 197
  • 1
  • 8
2
char.ToUpper(User.Identity.Name[0]) + User.Identity.Name.Substring(1)
hutchonoid
  • 32,982
  • 15
  • 99
  • 104
2

You don't need any code for that, just use plain CSS:

<h3>Welcome Home<strong style="text-transform: capitalize;"><%: User.Identity.Name %></strong></h3>

Working in all browsers as far as I could see.

Live test case.

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208