The above is. I originally wanted to integrate it into my own tools, but after searching, there was no relevant code in China, so I had to go to a foreign website to search. You can simply apply the classes written by others. Just think about it. Haha. In addition, you can see how cool Microsoft Visual Studio 2012 is. That's awesome. I like this interface, although not quite suitable.
On VS2012.
No nonsense. Go to 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 )));
}
}
How to use it. I can demonstrate it.
Private void button11_Click (object sender, EventArgs e)
{
RichTextBox4.Text = Spinner. Spin (richTextBox3.Text );
}
Attach another SPINNER class. You just need to select a class.
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 );
}
In addition, I would like to ask for the invitation code for various forums. I found that a lot of black and wide forums require an invitation code or an original article. I hope that people who like aojing can hold a forum.
Email: shine52shine # 126.com