hi...im trying to captilize the first word of a line that was built with stringbuilder, but cant find the right way...
do i need to copy the word into a regular string and use ToUpper()?
it drive me nuts...
thanks for your help...Nuninio
nuninio
0
Newbie Poster
Recommended Answers
Jump to PostYou can split line by ' ' space, get words[0] -first word- capitalize it, then return this array to 1 string again.
Jump to PostTry this in a console app:
StringBuilder sb = new StringBuilder("this is a test");
Console.WriteLine(sb);
string str = sb.ToString();
char ch = str[0];
sb.Replace(ch, char.ToUpper(ch), 0, 1);
Console.WriteLine(sb);
Console.ReadKey();
Jump to PostStringBuilder is (as you know) an array of char.
So you can either loop through getting the first space to detect the word, and start looking for the return\line feed '\r\n' or just convert it to string.Here are a couple ways.
If only one line is in the …
All 10 Replies
Ramy Mahrous
401
Postaholic
Featured Poster
ddanbe
2,724
Professional Procrastinator
Featured Poster
Ramy Mahrous
commented:
Always helpful, correct
+6
Ramy Mahrous
401
Postaholic
Featured Poster
ddanbe
2,724
Professional Procrastinator
Featured Poster
JerryShaw
46
Posting Pro in Training
Ramy Mahrous
commented:
completely right
+6
Ramy Mahrous
401
Postaholic
Featured Poster
ddanbe
2,724
Professional Procrastinator
Featured Poster
JerryShaw
46
Posting Pro in Training
ddanbe
2,724
Professional Procrastinator
Featured Poster
subtercosm
0
Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.