Reg Expressions....

  • Thread starter Thread starter Amith Singh
  • Start date Start date
A

Amith Singh

Hello All,
I would like to write a function which reads a string and adds one blank
space if any word is greater than 50 characters. How to write these kind of
functions using regular expressions.
Thanks,
Amith
 
I would like to write a function which reads a string and adds one
blank space if any word is greater than 50 characters. How to write
these kind of functions using regular expressions.

Where do you want to place the blank space?
 
Regex r = new Regex(@"(?<string>\S{50,})", RegexOptions.Compiled |
RegexOptions.Multiline | RegexOptions.ExplicitCapture);
string newString = r.Replace(YOURSTRINGHERE, "${string} ");


that should work.

karl
 
My example simply added a string to the word that had more than 50
characters


hello this is a veryveryvery... long string
would do -->
hello this is a veryveryvery...<SPACE> long string

But Lucas is right, the requirements weren't all that clear...

Karl
 
My requirement is, in a string if any word is more than 50 characetrs add
one blank space and continue with the rest of the string. To have a string
which do not have any word more than 50 characters. The idea is to split the
word.
Thanks,
Amith
 
The code I gave almost does this, just get rid of the comma after the 50 -->
Regex r = new Regex(@"(?<string>\S{50})", RegexOptions.Compiled |
RegexOptions.Multiline | RegexOptions.ExplicitCapture);
string newString = r.Replace(YOURSTRINGHERE, "${string} ");

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


Amith Singh said:
My requirement is, in a string if any word is more than 50 characetrs add
one blank space and continue with the rest of the string. To have a string
which do not have any word more than 50 characters. The idea is to split the
word.
Thanks,
Amith
 

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

Back
Top