Regex help Again

B

barry

Hi

1 str = "Hello World !!!"

kindly help in removing extra spaces from the above text

2. str = "THE QUICK BLACK FOX JUMPED OVER THE LAZY DOG"

and to change first letter of above to caps.

TIA
Barry
 
J

Jesse Houwing

Hello Barry,
Hi

1 str = "Hello World !!!"

kindly help in removing extra spaces from the above text

2. str = "THE QUICK BLACK FOX JUMPED OVER THE LAZY DOG"

and to change first letter of above to caps.


1)

Regex.Replace(str, @"\s{2,}", "", RegexOptions.None);

2) This line will do the trick

string s = Regex.Replace(str, @"\w+", new MatchEvaluator(this.MakeTitleCase),
RegexOptions.None);

You also need this function

private string MakeTitleCase(Match m)
{
return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(m.Value.ToLower());
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

SQL Insert problems 2
Extra spaces before and after text. 4
Line length 14
RegEx Help needed 4
Tough (for me) regex case 14
Key Words 3
Need Help! Paragraph formatting problem 1
How to get the text with regex? 1

Top