473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Reg Expressions....

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
Nov 18 '05 #1
5 1454
"Amith Singh" <Am******@hotmail.com> wrote in
news:Op**************@TK2MSFTNGP15.phx.gbl:
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?

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 18 '05 #2
Regex r = new Regex(@"(?<string>\S{50,})", RegexOptions.Compiled |
RegexOptions.Multiline | RegexOptions.ExplicitCapture);
string newString = r.Replace(YOURSTRINGHERE, "${string} ");
that should work.

karl
"Amith Singh" <Am******@hotmail.com> wrote in message
news:Op**************@TK2MSFTNGP15.phx.gbl...
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

Nov 18 '05 #3
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 ASP.Net tutorials
http://www.openmymind.net/
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn**************************@140.99.99.130...
"Amith Singh" <Am******@hotmail.com> wrote in
news:Op**************@TK2MSFTNGP15.phx.gbl:
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?

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 18 '05 #4
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

"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn**************************@140.99.99.130...
"Amith Singh" <Am******@hotmail.com> wrote in
news:Op**************@TK2MSFTNGP15.phx.gbl:
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?

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 18 '05 #5
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" <Am******@hotmail.com> wrote in message
news:OF**************@TK2MSFTNGP11.phx.gbl...
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

"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn**************************@140.99.99.130...
"Amith Singh" <Am******@hotmail.com> wrote in
news:Op**************@TK2MSFTNGP15.phx.gbl:
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?

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/


Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

72
by: Raymond Hettinger | last post by:
Peter Norvig's creative thinking triggered renewed interest in PEP 289. That led to a number of contributors helping to re-work the pep details into a form that has been well received on the...
2
by: Sehboo | last post by:
Hi, I have several regular expressions that I need to run against documents. Is it possible to combine several expressions in one expression in Regex object. So that it is faster, or will I...
1
by: Sehboo | last post by:
Hi, I have several regular expressions that I need to run against documents. Is it possible to combine several expressions in one expression in Regex object. So that it is faster, or will I...
4
by: Együd Csaba | last post by:
Hi All, I'd like to "compress" the following two filter expressions into one - assuming that it makes sense regarding query execution performance. .... where (adate LIKE "2004.01.10 __:30" or...
2
by: aarklon | last post by:
Hi all, Recently i was reading a c book which contained a section called C pitfalls. it had a paragraph on the following lines:- ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.