Alternative to using MatchCollections

T

TheReckter

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 = R.Next(0, 10);
i++;
}
i = 0;
foreach (Match Match in SymReg)
{
Match.Value.Replace("",
Buff.ToString());
i++;
}
textBox1.Text = main;
break;
}
i = 0;

x++;
}
}
 
M

Marc Gravell

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
 

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

Top