473,394 Members | 2,048 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,394 software developers and data experts.

Alternative to using MatchCollections

The following method does not seem to work because MatchCollections are
read only, does anyone know another way I could accomplish a simillar
thing, this would be greatly appreciated, thankyou.

char[] RandSymbols = new char[] { '!', '@', '#', '$', '%', '^',
'&', '*', ':', ';' };

private void FuncRand()
{
Random R = new Random();
Regex RegSymbol = new Regex(@"\[s\]");
string main = Main.Text;
int[] Buff = new int[50];
int x = 0;
int i = 0;

switch (x)
{
case 0:
MatchCollection SymReg =
RegSymbol.Matches(main);
i = 0;
while (i < 50)
{
Buff[i] = R.Next(0, 10);
i++;
}
i = 0;
foreach (Match Match in SymReg)
{
Match.Value.Replace("[s]",
Buff[i].ToString());
i++;
}
textBox1.Text = main;
break;
}
i = 0;

x++;
}
}

Oct 8 '06 #1
5 1594
If I understand the intent correctly, could you use (in a loop,
"Matches" times):
main = RegSymbol.Replace(main, Buff[i++].ToString(),1);

Not terribly efficient for long strings (multiple matches), but may
work.

Marc

Oct 8 '06 #2
Thankyou very much, exactly what I was looking for

Oct 8 '06 #3
Use the Regex.Replace overload that takes a MatchEvaluator delegate to do
this (no loop necessary). See

http://msdn2.microsoft.com/en-us/library/cft8645c.aspx

--
HTH,

Kevin Spencer
Microsoft MVP
Computer Control Freak
http://unclechutney.blogspot.com

A man, a plan, a canal, a palindrome that has.. oh, never mind.

<Th********@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
The following method does not seem to work because MatchCollections are
read only, does anyone know another way I could accomplish a simillar
thing, this would be greatly appreciated, thankyou.

char[] RandSymbols = new char[] { '!', '@', '#', '$', '%', '^',
'&', '*', ':', ';' };

private void FuncRand()
{
Random R = new Random();
Regex RegSymbol = new Regex(@"\[s\]");
string main = Main.Text;
int[] Buff = new int[50];
int x = 0;
int i = 0;

switch (x)
{
case 0:
MatchCollection SymReg =
RegSymbol.Matches(main);
i = 0;
while (i < 50)
{
Buff[i] = R.Next(0, 10);
i++;
}
i = 0;
foreach (Match Match in SymReg)
{
Match.Value.Replace("[s]",
Buff[i].ToString());
i++;
}
textBox1.Text = main;
break;
}
i = 0;

x++;
}
}

Oct 8 '06 #4
Cheers Kevin; something new every day ;-p

Marc

Oct 8 '06 #5
Same here, Marc!

--
:-D

Kevin Spencer
Microsoft MVP
Computer Control Freak
http://unclechutney.blogspot.com

A man, a plan, a canal, a palindrome that has.. oh, never mind.

"Marc Gravell" <ma**********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Cheers Kevin; something new every day ;-p

Marc

Oct 9 '06 #6

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

Similar topics

46
by: Robin Becker | last post by:
It seems that the rotor module is being deprecated in 2.3, but there doesn't seem to be an obvious alternative. I'm using it just for obfuscation. It seems we have ssl available in 2.3 for sockets,...
99
by: Paul McGuire | last post by:
There are a number of messages on the python-dev mail list that indicate that Guido is looking for some concensus to come from this list as to what *one* alternative syntax for decorators we would...
28
by: Paul McGuire | last post by:
Well, after 3 days of open polling, the number of additional votes have dropped off pretty dramatically. Here are the results so far: Total voters: 55 (with 3 votes each) Votes for each choice...
62
by: christopher diggins | last post by:
Since nobody responded to my earlier post , I thought I would try to explain what I am doing a bit differently. When multiply inheriting pure virtual (abstract) base classes, a class obviously...
1
by: prasaddevivara | last post by:
I am using the outerHTML property to modify the HTML of existin elements in a web page in Internet Explorer. But same outerHTM property is not working in firefox browser, Anybody can tell me a...
20
by: Tammy | last post by:
What would be a good alternative to using frames? I need something that will section my webpage into two halves and can change both frames on a single click. Thanks in Advance, Tammy
10
by: Michael Culley | last post by:
In vb6 it was possible to create an exe as an activeX exe and communicate between 2 apps. Now we have remoting which requires opening a tcp port to listen on, which seems kinda crappy cause another...
1
by: Andrew Gomes | last post by:
Does anyone know if there is an alternative to reading Exchange 2003 public folders with WMI? I am using WMI in VB.NET to read a list of public folders on an Exchange 2003 server. My problem is...
0
by: sachintandon | last post by:
Hello all, Thanks in advance for your help I have a problem in sending emails, my requirement is to send multipart alternative emails with attachments, I'm able to send text with attachments or...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.