Alternative to using MatchCollections

  • Thread starter Thread starter TheReckter
  • Start date Start date
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++;
}
}
 
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
 
Back
Top