有用代码收集(不断增加,方便自己找)
一个还不错的产生随机密码的方法
用Javascript选中文本框的文字
<input type="text" onfocus="this.select()" value="点击选中我">
问:如何把整数转成有固定长度的字符串?
答:使用下列代码可以输出长度为4的字符串,即生成“0012”
int theValue = 12;
theValue.ToString("0000");
1 private static char[] constant={
2 '0','1','2','3','4','5','6','7','8','9',
3 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
4 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
5 };
6 public static string GenerateRandom(int Length)
7 {
8 System.Text.StringBuilder newRandom = new System.Text.StringBuilder(62);
9 Random rd= new Random();
10 for(int i=0;i<Length;i++)
11 {
12 newRandom.Append(constant[rd.Next(62)]);
13 }
14 return newRandom.ToString();
15 }
2 '0','1','2','3','4','5','6','7','8','9',
3 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
4 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
5 };
6 public static string GenerateRandom(int Length)
7 {
8 System.Text.StringBuilder newRandom = new System.Text.StringBuilder(62);
9 Random rd= new Random();
10 for(int i=0;i<Length;i++)
11 {
12 newRandom.Append(constant[rd.Next(62)]);
13 }
14 return newRandom.ToString();
15 }
用Javascript选中文本框的文字
<input type="text" onfocus="this.select()" value="点击选中我">
问:如何把整数转成有固定长度的字符串?
答:使用下列代码可以输出长度为4的字符串,即生成“0012”
int theValue = 12;
theValue.ToString("0000");