C#_取随机字符

1.多位数字字母组成,每位取值0-9A-Z

 1     /// <summary>
 2     /// 获取下一个顺序码根据上一个(数字字母组合)
 3     /// </summary>
 4     /// <param name="str">上一个顺序码</param>
 5     /// <returns></returns>
 6     public static string ESequenceCode(string code)
 7     {
 8         if (string.IsNullOrWhiteSpace(code))
 9         {
10             return "";
11         }
12         code = code.ToUpper();
13         int max = 90; int min = 48;
14         //数组48-57英文65-90(大写)/97-122(小写)
15         char[] strs = code.ToCharArray();
16         ASCIIEncoding ascii = new ASCIIEncoding();
17         for (int i = strs.Length - 1; i > -1; i--)
18         {
19             int ascII = ascii.GetBytes(strs[i].ToString())[0];
20             int ascIINew = (ascII == max ? min : (ascII + (ascII == 57 ? 8 : 1)));
21             byte[] byteArray = new byte[] { (byte)ascIINew };
22             strs[i] = Convert.ToChar(ascii.GetString(byteArray));
23             if (ascII != max)
24             {
25                 break;
26             }
27         }
28         return string.Join("", strs);
29     }
View Code

 

posted @ 2015-07-10 11:26  灰色雨逸  阅读(409)  评论(0编辑  收藏  举报