473,397 Members | 1,974 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,397 software developers and data experts.

Multiple Occurances Of Value In String

I am wanting to find any instance in a string where more then on occurance of a value occurs and replace it with a single occurance of the value. Specifically I want to search a text field and find any time where more then a single ' (tic) occurs in succession, and replace it with a single ' (tic).

Can this be done with a RegularExpression? Any example of how to do this?
Nov 18 '05 #1
4 1604
You don't need to use regular expressions.
Try this

private string ReplaceString ( string Input )

{

if ( Input.IndexOf("''") != -1 )

Input = ReplaceString( Input.Replace("''", "'") );

return Input;

}

where Input is the string for search the ' symbol

Regards
Martin

"Jim Heavey" <Ji*******@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.com...
I am wanting to find any instance in a string where more then on occurance of a value occurs and replace it with a single occurance of the value.
Specifically I want to search a text field and find any time where more then
a single ' (tic) occurs in succession, and replace it with a single ' (tic).
Can this be done with a RegularExpression? Any example of how to do this?

Nov 18 '05 #2
Hallo Jim
"Jim Heavey" <Ji*******@discussions.microsoft.com> schrieb im Newsbeitrag
news:53**********************************@microsof t.com...
I am wanting to find any instance in a string where more then on occurance of a value occurs and replace it with a single occurance of the value.
Specifically I want to search a text field and find any time where more then
a single ' (tic) occurs in succession, and replace it with a single ' (tic).
Can this be done with a RegularExpression? Any example of how to do this?

Do you mean that u want to do that with every possible value? so if youd
have a string like that:

aa++bb77jjkk..--hhjjkkll

it would return

a+b7jk.-hjkl

if you just want to replace '' with ' you could do something like this:

txtUser.Text.Replace("''", "'")

or for +

txtUser.Text.Replace("++", "+")

if you tryin to prevent a user to use sql injection in some of your forms, i
suggest you construct more security functions than that.

regards benni
Nov 18 '05 #3
It won't be a problem
i've tested it with 3, 4,5 even 7 tic's and everything works fine ( if you
see the code the function is calling recursive to check if there is more
double tic's after replacing )

Regards
Martin

"Jim Heavey" <Ji*******@discussions.microsoft.com> wrote in message
news:2E**********************************@microsof t.com...
This will work fine when you know you have '', but what about when you have 3 or 4 tic's? I know that I could write 10 replace statements, but I
was thinking there was an easier way...sy with a regular expression?

Nov 18 '05 #4
But if you still want to use regular expressions you can use this

System.Text.RegularExpressions.Regex r = new
System.Text.RegularExpressions.Regex(@"'+");
textBox2.Text = r.Replace(textBox1.Text, "'");

Regards
Martin

"Jim Heavey" <Ji*******@discussions.microsoft.com> wrote in message
news:2E**********************************@microsof t.com...
This will work fine when you know you have '', but what about when you have 3 or 4 tic's? I know that I could write 10 replace statements, but I
was thinking there was an easier way...sy with a regular expression?

Nov 18 '05 #5

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

Similar topics

5
by: Manu | last post by:
Hi, Here's what i want to accomplish. I want to make a list of frequenctly occuring words in a group of files along with the no of occurances of each The brute force method will be to read the...
3
by: Xah Lee | last post by:
if i have mytext.replace(a,b) how to find out many many occurances has been replaced? Xah xah@xahlee.org ∑ http://xahlee.org/
4
by: David Warner | last post by:
Greetings! In looking into some C coding, I am looking for the C function that will search for multiple occurances of a same character in a string. For Instance: char str = "We the people...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
2
by: Peter | last post by:
What is the most efficient way to count occurances of charaters in a string? IE. Searching for ',' in a comma del file.
1
by: RSH | last post by:
Hi, i have a situation where I have a string read from a file. The string format looks like this <HEADERROWdynamic number of characters </HEADERROW> dynamic number of rows <HEADERROWdynamic...
37
by: bahoo | last post by:
Hi, I have a list like and as output I want If I myList.remove('0024') then only the first instance of '0024' is removed.
4
by: Chris | last post by:
Hi, I have imported a spreadsheet into an access databsae and have noticed that there are multiple occurances of exactly the same record. I would like to know if there is a way of deleting the...
2
by: Smokey Grindle | last post by:
any fast way to do this? I just need to check if if a string which could have a lot of characters in it if it has numbers and count the number of numbers in the string. thanks!
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.