public static string AutoUpperFirstChar(string word) { string chuanHoa = Memory.GetConfig(GxConstants.CF_CHUANHOA_TRONGNGOAC); if (chuanHoa == "") { chuanHoa = "3"; } FontCase fontCase = (FontCase)int.Parse(chuanHoa); bool autoConvertSignPos = !(Memory.GetConfig(GxConstants.CF_CHUANHOA_TUDOIDAU) == GxConstants.CF_FALSE); bool autoConvertCharCode = !(Memory.GetConfig(GxConstants.CF_CHUANHOA_TUCHUYENMA) == GxConstants.CF_FALSE); return(AutoUpperFirstChar(word, fontCase, autoConvertSignPos, autoConvertCharCode)); }
public static string AutoUpperFirstChar(string word, FontCase fontCaseInQuote, bool autoConvertSignPosition, bool autoConvertCharCode) { //string[] splits = word.Split("~`!@#$%^&*()-+=|\\{[]}:;'\"<,>.?/\t\n\r".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); string[] splits = word.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); string specialChars = "(){[]}<>"; if (splits != null && splits.Length > 0) { for (int i = 0; i < splits.Length; i++) { if (splits[i].Length > 1) { string firsChar = splits[i].Substring(0, 1); if (specialChars.Contains(firsChar)) { if (fontCaseInQuote == FontCase.Normal) //Neu gap ky tu dac biet thi bo qua khong lam gi het { continue; } else if (fontCaseInQuote == FontCase.UpperCaseFirstChar) { //chuan hoa nhung tru cac ky tu dac biet. Vi du: nguyen van an (mr)=> Nguyen Van An (Mr) chu khong phai Nguyen Van An (mr) for (int k = 0; k < splits[i].Length; k++) { //tim ky tu dau tien khong phai la ky tu dac biet if (specialChars.Contains(splits[i].Substring(k, 1))) { continue; } //neu tim thay if (k == 0) //chuoi khong bat dau bang ky tu dac biet { splits[i] = string.Concat(splits[i].Substring(0, 1).ToUpper(), splits[i].Substring(1).ToLower()); } else if (k == splits[i].Length - 1) //chuoi ky tu cuoi cung moi la ky tu binh thuong { splits[i] = string.Concat(splits[i].Substring(0, splits[i].Length - 1), splits[i][k].ToString().ToUpper()); } else //ngoai cac truong hop tren { splits[i] = string.Concat(splits[i].Substring(0, k), splits[i][k].ToString().ToUpper(), splits[i].Substring(k + 1).ToLower()); } break; } } else if (fontCaseInQuote == FontCase.UpperCase) { splits[i] = splits[i].ToUpper(); } else if (fontCaseInQuote == FontCase.LowerCase) { splits[i] = splits[i].ToLower(); } } else { splits[i] = string.Concat(splits[i].Substring(0, 1).ToUpper(), splits[i].Substring(1).ToLower()); } } else if (splits[i].Length == 1) { splits[i] = splits[i].ToUpper(); } } } word = string.Join(" ", splits); if (autoConvertCharCode) { convertFont.Convert(ref word, FontIndex.iUTH, FontIndex.iUNI); } if (autoConvertSignPosition) { word = Memory.ChuanHoaDau(word); } return(word); }