程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> c# spinner格式處理類

c# spinner格式處理類

編輯:C#入門知識



 
 
 
以上是效果圖。本來想整合到自己的工具上的,但是搜索了一下,國內的沒有相關的代碼,只好去國外網站上去搜索了。別人寫好的類,直接套用就好了。就懶的自己想了。呵呵。另外炫下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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved