【发布时间】:2015-04-04 08:55:13
【问题描述】:
我想创建一种在字符串中的字符之间插入随机十六进制颜色的方法。这就是我到目前为止所拥有的。
`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;
}`
这使得字符串"input" 看起来像[FF0000]I[FF0000]n[FF0000]p[FF0000]u[FF0000]t"。如何每次都使十六进制代码成为一个新的随机数?
【问题讨论】:
-
使用相同的
Random对象。
标签: c# .net random replace colors