//------------------------------------------------------------ // Game Framework // Copyright © 2013-2020 Jiang Yin. All rights reserved. // Homepage: https://gameframework.cn/ // Feedback: mailto:ellan@gameframework.cn //------------------------------------------------------------ using System; using System.Text; namespace ET { public static partial class Utility { /// /// 字符相关的实用函数。 /// public static class Text { [ThreadStatic] private static StringBuilder s_CachedStringBuilder = null; /// /// 获取格式化字符串。 /// /// 字符串格式。 /// 字符串参数 0。 /// 格式化后的字符串。 public static string Format(string format, object arg0) { if (format == null) { throw new System.Exception("Format is invalid."); } CheckCachedStringBuilder(); s_CachedStringBuilder.Length = 0; s_CachedStringBuilder.AppendFormat(format, arg0); return s_CachedStringBuilder.ToString(); } /// /// 获取格式化字符串。 /// /// 字符串格式。 /// 字符串参数 0。 /// 字符串参数 1。 /// 格式化后的字符串。 public static string Format(string format, object arg0, object arg1) { if (format == null) { throw new System.Exception("Format is invalid."); } CheckCachedStringBuilder(); s_CachedStringBuilder.Length = 0; s_CachedStringBuilder.AppendFormat(format, arg0, arg1); return s_CachedStringBuilder.ToString(); } /// /// 获取格式化字符串。 /// /// 字符串格式。 /// 字符串参数 0。 /// 字符串参数 1。 /// 字符串参数 2。 /// 格式化后的字符串。 public static string Format(string format, object arg0, object arg1, object arg2) { if (format == null) { throw new System.Exception("Format is invalid."); } CheckCachedStringBuilder(); s_CachedStringBuilder.Length = 0; s_CachedStringBuilder.AppendFormat(format, arg0, arg1, arg2); return s_CachedStringBuilder.ToString(); } /// /// 获取格式化字符串。 /// /// 字符串格式。 /// 字符串参数。 /// 格式化后的字符串。 public static string Format(string format, params object[] args) { if (format == null) { throw new System.Exception("Format is invalid."); } if (args == null) { throw new System.Exception("Args is invalid."); } CheckCachedStringBuilder(); s_CachedStringBuilder.Length = 0; s_CachedStringBuilder.AppendFormat(format, args); return s_CachedStringBuilder.ToString(); } private static void CheckCachedStringBuilder() { if (s_CachedStringBuilder == null) { s_CachedStringBuilder = new StringBuilder(1024); } } } } }