/// <summary> /// 字符串的字母是否全小写[true:全小写;false:大小写混合] /// </summary> /// <param name="str">字符串</param> /// <returns>true:全小写;false:大小写混合</returns> public static bool IsAllLower(this string str) { char ch; for (int i = 0; i < str.Length; i++) { ch = str[i]; if (CharEx.IsLetter(ch) && CharEx.IsLetterUpper(ch)) { return(false); } } return(true); //bool result = true; //NExtendObject.DisorderLoop(str, (ch) => //{ // if (NExtendChar.IsLetter(ch) && NExtendChar.IsLetterUpper(ch)) // { // result = false; // return false; // } // return true; //}); //return result; //if (string.IsNullOrEmpty(str)) //{ // throw new ArgumentNullException(NExtendObject.GetVarName(xx => str)); //} ////已计算的中文字符个数 //bool result = true; //int length = str.Length / 2; //if (str.Length % 2 != 0) //{ // length += 1; //} //************************************************* // * fp pl pr rp // * |-->| |<--|-->| |<--| // * |______________________|______________________| // **************************************************/ //int fp = 0; //int pl = length - 1; //int pr = 0; //int rp = str.Length - 1; //char ch; ////fp,pl,pr,rp为四个方向移动的索引指针 //for (fp = 0, pr = length; fp < length; fp++, pr++) //{ // if (fp <= pl) // { // ch = str[fp]; // if (NExtendString.IsLetter(ch) && NExtendString.IsLetterUpper(ch)) // { // result = false; // break; // } // } // if (pl > fp) // { // ch = str[pl]; // if (NExtendString.IsLetter(ch) && NExtendString.IsLetterUpper(ch)) // { // result = false; // break; // } // pl--; // } // if (pr <= rp) // { // ch = str[pr]; // if (NExtendString.IsLetter(ch) && NExtendString.IsLetterUpper(ch)) // { // result = false; // break; // } // } // if (rp > pr) // { // ch = str[rp]; // if (NExtendString.IsLetter(ch) && NExtendString.IsLetterUpper(ch)) // { // result = false; // break; // } // rp--; // } //} //return result; }
/// <summary> /// 计算字符串中包含的中文字符数 /// </summary> /// <param name="str">待计算的字符串</param> /// <returns>字符串中包含的中文字符数</returns> public static int CalculateChineseCharCount(this string str) { //已计算的中文字符个数 int chineseCharCount = 0; //NExtendObject.DisorderLoop(str, (ch) => //{ // if (NExtendChar.IsChineseChar(ch)) // { // chineseCharCount++; // } // return true; //}); for (int i = 0; i < str.Length; i++) { if (CharEx.IsChineseChar(str[i])) { chineseCharCount++; } } return(chineseCharCount); //if (str == null) //{ // throw new ArgumentNullException(NExtendObject.GetVarName(xx => str)); //} ////空字符串返回0 //if (string.IsNullOrEmpty(str)) //{ // return 0; //} ////已计算的中文字符个数 //int chineseCharCount = 0; //int length = str.Length / 2; //if (str.Length % 2 != 0) //{ // length += 1; //} //************************************************* // * fp pl pr rp // * |-->| |<--|-->| |<--| // * |______________________|______________________| // **************************************************/ //int fp = 0; //int pl = length - 1; //int pr = 0; //int rp = str.Length - 1; ////fp,pl,pr,rp为四个方向移动的索引指针 //for (fp = 0, pr = length; fp < length; fp++, pr++) //{ // if (fp <= pl && NExtendChar.IsChineseChar(str[fp])) // { // chineseCharCount++; // } // if (pl > fp) // { // if (NExtendChar.IsChineseChar(str[pl])) // { // chineseCharCount++; // } // pl--; // } // if (pr <= rp && NExtendChar.IsChineseChar(str[pr])) // { // chineseCharCount++; // } // if (rp > pr) // { // if (NExtendChar.IsChineseChar(str[rp])) // { // chineseCharCount++; // } // rp--; // } //} //return chineseCharCount; }