using UnityEngine; using System.Collections; using System.Text; using System; using System.Collections.Generic; public partial class StringUtil { //自定义字符串函数公用的StringBuilder static StringBuilder _customSB = new StringBuilder(); //共享的StringBuilder static StringBuilder shareSB = new StringBuilder(); #region Concat /// /// 拼接字符串(2个) /// /// /// /// public static string Concat(string a1, string a2) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); return _customSB.ToString(); } /// /// 拼接字符串(3个) /// /// /// /// /// public static string Concat(string a1, string a2, string a3) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); _customSB.Append(a3); return _customSB.ToString(); } /// /// 拼接字符串(4个) /// /// /// /// /// /// public static string Concat(string a1, string a2, string a3, string a4) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); _customSB.Append(a3); _customSB.Append(a4); return _customSB.ToString(); } /// /// 拼接字符串(5个) /// /// /// /// /// /// /// public static string Concat(string a1, string a2, string a3, string a4, string a5) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); _customSB.Append(a3); _customSB.Append(a4); _customSB.Append(a5); return _customSB.ToString(); } /// /// 拼接字符串(6个) /// /// /// /// /// /// /// /// public static string Concat(string a1, string a2, string a3, string a4, string a5, string a6) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); _customSB.Append(a3); _customSB.Append(a4); _customSB.Append(a5); _customSB.Append(a6); return _customSB.ToString(); } /// /// 拼接字符串(7个) /// /// /// /// /// /// /// /// /// public static string Concat(string a1, string a2, string a3, string a4, string a5, string a6, string a7) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); _customSB.Append(a3); _customSB.Append(a4); _customSB.Append(a5); _customSB.Append(a6); _customSB.Append(a7); return _customSB.ToString(); } /// /// 拼接字符串(8个) /// /// /// /// /// /// /// /// /// /// public static string Concat(string a1, string a2, string a3, string a4, string a5, string a6, string a7, string a8) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); _customSB.Append(a3); _customSB.Append(a4); _customSB.Append(a5); _customSB.Append(a6); _customSB.Append(a7); _customSB.Append(a8); return _customSB.ToString(); } /// /// 拼接字符串(9个) /// /// /// /// /// /// /// /// /// /// /// public static string Concat(string a1, string a2, string a3, string a4, string a5, string a6, string a7, string a8, string a9) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); _customSB.Append(a3); _customSB.Append(a4); _customSB.Append(a5); _customSB.Append(a6); _customSB.Append(a7); _customSB.Append(a8); _customSB.Append(a9); return _customSB.ToString(); } /// /// 拼接字符串(10个) /// /// /// /// /// /// /// /// /// /// /// /// public static string Concat(string a1, string a2, string a3, string a4, string a5, string a6, string a7, string a8, string a9, string a10) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); _customSB.Append(a3); _customSB.Append(a4); _customSB.Append(a5); _customSB.Append(a6); _customSB.Append(a7); _customSB.Append(a8); _customSB.Append(a9); _customSB.Append(a10); return _customSB.ToString(); } /// /// 拼接字符串(11个) /// /// /// /// /// /// /// /// /// /// /// /// /// public static string Concat(string a1, string a2, string a3, string a4, string a5, string a6, string a7, string a8, string a9, string a10, string a11) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); _customSB.Append(a3); _customSB.Append(a4); _customSB.Append(a5); _customSB.Append(a6); _customSB.Append(a7); _customSB.Append(a8); _customSB.Append(a9); _customSB.Append(a10); _customSB.Append(a11); return _customSB.ToString(); } /// /// 拼接字符串(12个) /// /// /// /// /// /// /// /// /// /// /// /// /// /// public static string Concat(string a1, string a2, string a3, string a4, string a5, string a6, string a7, string a8, string a9, string a10, string a11, string a12) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); _customSB.Append(a3); _customSB.Append(a4); _customSB.Append(a5); _customSB.Append(a6); _customSB.Append(a7); _customSB.Append(a8); _customSB.Append(a9); _customSB.Append(a10); _customSB.Append(a11); _customSB.Append(a12); return _customSB.ToString(); } /// /// 拼接字符串(13个) /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public static string Concat(string a1, string a2, string a3, string a4, string a5, string a6, string a7, string a8, string a9, string a10, string a11, string a12, string a13) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); _customSB.Append(a3); _customSB.Append(a4); _customSB.Append(a5); _customSB.Append(a6); _customSB.Append(a7); _customSB.Append(a8); _customSB.Append(a9); _customSB.Append(a10); _customSB.Append(a11); _customSB.Append(a12); _customSB.Append(a13); return _customSB.ToString(); } /// /// 拼接字符串(14个) /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public static string Concat(string a1, string a2, string a3, string a4, string a5, string a6, string a7, string a8, string a9, string a10, string a11, string a12, string a13, string a14) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); _customSB.Append(a3); _customSB.Append(a4); _customSB.Append(a5); _customSB.Append(a6); _customSB.Append(a7); _customSB.Append(a8); _customSB.Append(a9); _customSB.Append(a10); _customSB.Append(a11); _customSB.Append(a12); _customSB.Append(a13); _customSB.Append(a14); return _customSB.ToString(); } /// /// 拼接字符串(15个) /// public static string Concat(string a1, string a2, string a3, string a4, string a5, string a6, string a7, string a8, string a9, string a10, string a11, string a12, string a13, string a14, string a15) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); _customSB.Append(a3); _customSB.Append(a4); _customSB.Append(a5); _customSB.Append(a6); _customSB.Append(a7); _customSB.Append(a8); _customSB.Append(a9); _customSB.Append(a10); _customSB.Append(a11); _customSB.Append(a12); _customSB.Append(a13); _customSB.Append(a14); _customSB.Append(a15); return _customSB.ToString(); } /// /// 拼接字符串(16个) /// public static string Concat(string a1, string a2, string a3, string a4, string a5, string a6, string a7, string a8, string a9, string a10, string a11, string a12, string a13, string a14, string a15, string a16) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); _customSB.Append(a3); _customSB.Append(a4); _customSB.Append(a5); _customSB.Append(a6); _customSB.Append(a7); _customSB.Append(a8); _customSB.Append(a9); _customSB.Append(a10); _customSB.Append(a11); _customSB.Append(a12); _customSB.Append(a13); _customSB.Append(a14); _customSB.Append(a15); _customSB.Append(a16); return _customSB.ToString(); } /// /// 拼接字符串(17个) /// public static string Concat(string a1, string a2, string a3, string a4, string a5, string a6, string a7, string a8, string a9, string a10, string a11, string a12, string a13, string a14, string a15, string a16, string a17) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); _customSB.Append(a3); _customSB.Append(a4); _customSB.Append(a5); _customSB.Append(a6); _customSB.Append(a7); _customSB.Append(a8); _customSB.Append(a9); _customSB.Append(a10); _customSB.Append(a11); _customSB.Append(a12); _customSB.Append(a13); _customSB.Append(a14); _customSB.Append(a15); _customSB.Append(a16); _customSB.Append(a17); return _customSB.ToString(); } /// /// 拼接字符串(18个) /// public static string Concat(string a1, string a2, string a3, string a4, string a5, string a6, string a7, string a8, string a9, string a10, string a11, string a12, string a13, string a14, string a15, string a16, string a17, string a18) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); _customSB.Append(a3); _customSB.Append(a4); _customSB.Append(a5); _customSB.Append(a6); _customSB.Append(a7); _customSB.Append(a8); _customSB.Append(a9); _customSB.Append(a10); _customSB.Append(a11); _customSB.Append(a12); _customSB.Append(a13); _customSB.Append(a14); _customSB.Append(a15); _customSB.Append(a16); _customSB.Append(a17); _customSB.Append(a18); return _customSB.ToString(); } /// /// 拼接字符串(19个) /// public static string Concat(string a1, string a2, string a3, string a4, string a5, string a6, string a7, string a8, string a9, string a10, string a11, string a12, string a13, string a14, string a15, string a16, string a17, string a18, string a19) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); _customSB.Append(a3); _customSB.Append(a4); _customSB.Append(a5); _customSB.Append(a6); _customSB.Append(a7); _customSB.Append(a8); _customSB.Append(a9); _customSB.Append(a10); _customSB.Append(a11); _customSB.Append(a12); _customSB.Append(a13); _customSB.Append(a14); _customSB.Append(a15); _customSB.Append(a16); _customSB.Append(a17); _customSB.Append(a18); _customSB.Append(a19); return _customSB.ToString(); } /// /// 拼接字符串(20个) /// public static string Concat(string a1, string a2, string a3, string a4, string a5, string a6, string a7, string a8, string a9, string a10, string a11, string a12, string a13, string a14, string a15, string a16, string a17, string a18, string a19, string a20) { _customSB.Remove(0, _customSB.Length); _customSB.Append(a1); _customSB.Append(a2); _customSB.Append(a3); _customSB.Append(a4); _customSB.Append(a5); _customSB.Append(a6); _customSB.Append(a7); _customSB.Append(a8); _customSB.Append(a9); _customSB.Append(a10); _customSB.Append(a11); _customSB.Append(a12); _customSB.Append(a13); _customSB.Append(a14); _customSB.Append(a15); _customSB.Append(a16); _customSB.Append(a17); _customSB.Append(a18); _customSB.Append(a19); _customSB.Append(a20); return _customSB.ToString(); } #endregion /// /// 获得公用的StringBuilder /// /// public static StringBuilder GetShareStringBuilder(bool bReset = true) { if (bReset) { shareSB.Remove(0, shareSB.Length); } return shareSB; } /// /// 格式化字符串 /// /// /// /// public static string Format(string format, params object[] args) { try { _customSB.Remove(0, _customSB.Length); _customSB.AppendFormat(format, args); return _customSB.ToString(); } catch (Exception e) { LogHelper.LogError(e.Message); return format; } } /// /// 替换\\n 为\n /// /// /// public static string ReplaceNewLineChar(string baseStr) { //if (!baseStr.Contains("\\n")) //{ // return baseStr; //} return baseStr.Replace("\\n", "\n"); } /// /// 替换转义字符 /// /// /// public static string ReplaceTranslateChar(string baseStr) { baseStr = baseStr.Replace("\\n", "\n"); baseStr = baseStr.Replace("\\t", "\t"); baseStr = baseStr.Replace("\\b", " "); return baseStr; } /// /// 替换\\s 为(全角)空格 /// /// /// public static string ReplaceNewBlankSpaceChar(string baseStr) { //if (!baseStr.Contains("\\s")) //{ // return baseStr; //} return baseStr.Replace("\\s", " "); } // 正则匹配空格规则 static System.Text.RegularExpressions.Regex SpaceRgx = null; private static string GetSpacePattern() { return "\\s(?![a-z]|\\s)"; } public static System.Text.RegularExpressions.Regex GetSpaceRgx() { if(SpaceRgx == null) { SpaceRgx = new System.Text.RegularExpressions.Regex(GetSpacePattern(), System.Text.RegularExpressions.RegexOptions.IgnoreCase); } return SpaceRgx; } // 处理英文混排时空格换行的问题 public static string ProSpace(string value) { if (string.IsNullOrEmpty(value)) return value; return ProSpaceSp(value); } private static string ProSpaceSp(string value) { return value.Replace("{sp}", "\u00A0"); } private static string ProSpaceNormal(string value) { return GetSpaceRgx().Replace(value, "\u00A0"); } /// /// 文本加持颜色 /// /// /// /// public static string UITextColor(string color, string text) { return StringUtil.Format("{1}", color, text); } /// /// 文本加持颜色 /// /// /// /// public static string UITextColor(Color color, string text) { return UITextColor(ColorUtility.ToHtmlStringRGBA(color), text); } /// /// 整数转字符串 /// /// /// /// /// public static string Int2StringLimit(int num, int limit, string param = "") { if (num < limit) { return num.ToString(param); } else { return limit.ToString(param); } } /// /// 替换为linux的斜杠 /// /// /// public static string StringSlashOfLinux(string str) { return str.Replace('\\', '/'); ; } /// /// 替换为win的斜杠 /// /// /// public static string StringSlashOfWin(string str) { return str.Replace('/', '\\'); ; } /// /// 服务器接收的字符串不可有竖线 /// /// /// public static string ToServerSafeString(string str) { return str.Replace("|", "/"); } public static string DictionaryConvertString(Dictionary dic) { _customSB.Remove(0, _customSB.Length); if(dic != null) { Dictionary.Enumerator itor = dic.GetEnumerator(); while(itor.MoveNext()) { _customSB.Append(itor.Current.Key); _customSB.Append(","); _customSB.Append(itor.Current.Value); _customSB.Append(";"); } } return _customSB.ToString(); } #region 数字转美式字符串 #if VERSION_OVERSEA_GAIYA && !(GAIYA_BURNING_GAME ||GAIYA_MYCARD_GAME) public static string Num2US(float num) { return num.ToString("n2"); } public static string Num2US(int num) { return num.ToString("n0"); } public static string Num2US(long num) { return num.ToString("n0"); } #else public static string Num2US(float num) { return num.ToString("n2").Replace(',',' '); } public static string Num2US(int num) { return num.ToString("n0").Replace(',', ' '); } public static string Num2US(long num) { return num.ToString("n0").Replace(',', ' '); } #endif #endregion }