1

I've seen a lot of threads in stackoverflow for that matter, and all of them solve the problem of upper casing the first letter while lower casing the rest, my question is how to leave the rest of the letters with whatever case they've got.

Haven't seen an answer for this yet, thanks in advance.

matan justme
  • 371
  • 3
  • 15
  • OP, my solution is not the best. Follow the link below for a better solution> https://stackoverflow.com/questions/4135317/make-first-letter-of-a-string-upper-case-with-maximum-performance – Maddy Nov 07 '18 at 00:13
  • This is not a duplicate, I don't know how u guys decide whether a question is a duplicate or not. I'll uppercase the part which prooves that it's not a duplicate, in case you didn't read it : "How to upper case first letter of every word, WHILE NOT LOWER CASING THE REST OF THE LETTERS", thanks in advance. – matan justme Nov 07 '18 at 00:20
  • 1
    I don't know C#, but the top answer in that duplicate link uses the line `return input.First().ToString().ToUpper() + input.Substring(1);`. That doesn't seem to effect anything but the first letter. It seems to do exactly what you want. – Carcigenicate Nov 07 '18 at 00:23
  • @Carcigenicate first letter of every word. – matan justme Nov 07 '18 at 00:23
  • 1
    "Based on the answers and the comments under the answers, many people think this is asking about capitalizing all words in the string. E.g. => Red House It isn't, but if that is what you seek, look for one of the answers that uses TitleInfo's ToTitleCase method. (NOTE: Those answers are incorrect for the question actually asked.)" – zzxyz Nov 07 '18 at 00:24
  • @zzxyz I've tried ToTitleCase, it's uppercasing the first letter and lower casing the rest, even though people say it's not (read about it a while ago). Try it with the input "aBGxZ" for example... i've upvoted your answer though. – matan justme Nov 07 '18 at 00:25
  • @matanjustme - fair enough. Looks like this shouldn't have been closed (marked as duplicate). I'm not sure a grab-bag of 37 answers to different questions is the best thing anyway. Try this `string uc = "hElLO hOw aRe YoU";` `string tc = Regex.Replace(uc, @"(^\w)|(\s\w)", m => m.Value.ToUpper());` tc seems to contain your expected output, I think. – zzxyz Nov 07 '18 at 00:40
  • @zzxyz i've created a function that's supposed to solve it right now, haven't tested it though. i'll upload it in pastebin tell me what are your thoughts. – matan justme Nov 07 '18 at 00:42
  • @zzxyz https://pastebin.com/2Nx3Frpg forgot to type cast to char before – matan justme Nov 07 '18 at 00:53
  • @zzxyz alright what i've made is working so i'll paste the question again and answer it, for the sake of the community and not for the sake of those who keep marking questions as duplicates for no reason. – matan justme Nov 07 '18 at 00:57
  • @matanjustme - You might try the regex since it's two lines of code. Or did it not work? – zzxyz Nov 07 '18 at 01:23

0 Answers0