- ///
- /// 是否是中文(是否全部是中文)
- ///
- ///
- ///
- public static bool ChineseReg(string text)
- {
- char[] charList = text.ToCharArray();
- for (int i = 0; i < charList.Length; i++)
- {
- int chfrom = Convert.ToInt32("4e00", 16); //范围(0x4e00~0x9fff)转换成int(chfrom~chend)
- int chend = Convert.ToInt32("9fff", 16);
- int code = Char.ConvertToUtf32(text, i);
- if (code < chfrom || code > chend)
- {
- return false; //没有中文
- }
-
- }
- return true; //有中文
- }
-
- ///
- /// 将string转换成二进制
- ///
- ///
- ///
- public static string GetBitValueString(string value)
- {
- string bitString = "";
-
- if (value != null && value != "")
- {
- long num = Convert.ToInt64(value);
- bitString = Convert.ToString(num, 2);
- char[] chArr = bitString.ToCharArray();
- bitString = String.Join("|", chArr);
-
- }
- return bitString;
- }
Char.ConvertToUtf32(text, i):
数值转化为对应的字符
char.ConvertFromUtf32(20013);// 将20013转换为对应的中文,“中”
结果为:中
字符转换为对应的数值
char.ConvertToUtf32(“中”, 0);//将字符转换为整型如果是中文则UTF码,英语就是对应的 ASCII码值,0表示索引值第一个字符
结果为:20013
学习自:字符和对应数值之间的转化_TaLinBoy的博客-CSDN博客_字符和数字之间的转换
Convert.ToInt64(value)
Convert.ToInt64(value, fromBase)
fromBase代表进制 2,8,10,16
示例:
Convert.ToInt64(“1001”, 2) ⇒ 9
Convert.ToInt64(“f”, 16) ⇒ 15
学习自:Convert.ToInt64(value, fromBase)_wangxiaopang1003的博客-CSDN博客
Convert.ToString(num, 2)

