123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace efunbox_xyyf_windows.util
- {
- public class TextUtils
- {
- //非空判断
- public static bool isEmpty(string str)
- {
- if (str == null || str.Equals("") || str.Length == 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- /**
- * 获取字符串
- * N 字符数量; 默认32位
- * number: 是否包含数字; 默认true
- * Lowercase:是否包含小写英文字母 默认false
- * capital:是否包含大写英文字母 默认true
- *
- * **/
- public static string GetRandomCharacters(int n = 32, bool Number = true, bool Lowercase = false, bool Capital = true)
- {
- StringBuilder tmp = new StringBuilder();
- Random rand = new Random();
- string characters = (Capital ? "ABCDEFGHIJKLMNOPQRSTUVWXYZ" : null) + (Number ? "0123456789" : null) + (Lowercase ? "abcdefghijklmnopqrstuvwxyz" : null);
- if (characters.Length < 1)
- {
- return (null);
- }
- for (int i = 0; i < n; i++)
- {
- tmp.Append(characters[rand.Next(0, characters.Length)].ToString());
- }
- return (tmp.ToString());
- }
- }
- }
|