I have a
DetailsView with a
and I want the input data be saved always with the first letter in capital.
"red" --> "Red" "red house" --> " Red house"
How can I achieve this maximizing performance?
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
ToTitleCase method. (Note: Those answers are incorrect for the question actually asked.)
See TextInfo.ToTitleCase documentation for caveats (doesn't touch all-caps words – they are considered acronyms; may lowercase letters in middle of words that "shouldn't" be lowered, e.g., "McDonald" → "Mcdonald"; not guaranteed to handle all culture-specific subtleties re capitalization rules.)
The question is ambiguous as to whether letters after the first should be forced to lower case. The accepted answer assumes that only the first letter should be altered. If you want to force all letters in the string except the first to be lower case, look for an answer containing
ToLower, and not containing ToTitleCase.