当前位置:编程学习 > C#/ASP.NET >>

c# spinner格式处理类



 
 
 
以上是效果图。本来想整合到自己的工具上的,但是搜索了一下,国内的没有相关的代码,只好去国外网站上去搜索了。别人写好的类,直接套用就好了。就懒的自己想了。呵呵。另外炫下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
补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,