以上是效果圖。本來想整合到自己的工具上的,但是搜索了一下,國內的沒有相關的代碼,只好去國外網站上去搜索了。別人寫好的類,直接套用就好了。就懶的自己想了。呵呵。另外炫下Microsoft Visual Studio 2012的黑酷吧。太牛逼了。喜歡死這個界面,雖然還不太適應。
上VS2012的深黑效果圖。
不廢話了,上CSHARP CONTENT SPINNER CODE:
public static class Spinner
{
//From http://www.xssxss.com
private readonly static Random Randomizer = new Random();
public static string Spin(string content)
{
const char OPEN_BRACE = '{';
const char CLOSE_BRACE = '}';
const char DELIMITER = '|';
var start = content.IndexOf(OPEN_BRACE);
var end = content.IndexOf(CLOSE_BRACE);
if (start == -1 && end == -1 || start == -1 || end < start)
{
return content;
}
if (end == -1)
{
throw new ArgumentException("Unbalanced brace.");
}
var substring = content.Substring(start + 1, content.Length - (start + 1));
var rest = Spin(substring);
end = rest.IndexOf(CLOSE_BRACE);
if (end == -1)
{
throw new ArgumentException("Unbalanced brace.");
}
var splits = rest.Substring(0, end).Split(DELIMITER);
var item = splits[Randomizer.Next(0, splits.Length)];
return content.Substring(0, start) + item + Spin(rest.Substring(end + 1, rest.Length - (end + 1)));
}
}
至於怎麼用。可以我的示范
private void button11_Click(object sender, EventArgs e)
{
richTextBox4.Text = Spinner.Spin(richTextBox3.Text);
}
附上另外一個SPINNER的類,大家看著選擇一個類用就好了
private string returnSpinnedPart(string part)
{
Random random = new Random();
string[] values = part.Split('|');
if (values.Length > 0)
return values[random.Next(0, values.Length)];
return "";
}
//From http://www.xssxss.com
private string returnSpinnedContent(string input)
{
string spinned = input;
try
{
Regex regexObj = new Regex(@"\{.*?\}", RegexOptions.Singleline);
MatchCollection m = regexObj.Matches(input);
foreach (Match match in m)
{
string part = returnSpinnedPart(match.Value.Replace("{", "").Replace("}", ""));
spinned = spinned.Replace(match.Value, part);
}
}
catch (ArgumentException ex)
{
MessageBox.Show("RegEx prob");
}
return spinned;
}
private void button12_Click(object sender, EventArgs e)
{
richTextBox4.Text = returnSpinnedContent(richTextBox3.Text);
}
另外求各大黑闊論壇邀請碼啊。發現一大堆黑闊論壇要邀請碼,要麼就得原創文章,俺木有原創,希望喜歡蒼井空的人們捧個場。
Email:shine52shine#126.com