mercredi 4 février 2015

C# Insert a random string in between characters in another string

I want to make a method that inserts a randomized hex color in between characters in a string. This is what I have so far.



`public static string colorString(string input)
{
var random = new System.Random();
string hexcolor = "[" + String.Format("{0:X6}", random.Next(0x1000000)) + "];
string output = Regex.Replace(input, ".{0}", "$0" + hexcolor);
return ouput;
}`


this makes like a string "input" look like [FF0000]I[FF0000]n[FF0000]p[FF0000]u[FF0000]t". How do I make the hexcode a new random every time?





Aucun commentaire:

Enregistrer un commentaire