/// <summary> /// 替换字符串,仅第一个匹配项 /// </summary> /// <param name="value">原始内容</param> /// <param name="oldValue">要替换的字符串</param> /// <param name="newValue">替换后的字符串</param> /// <returns></returns> private static string GetReplaceByFirst(string value, string oldValue, string newValue, StringComparison comparisonType = StringComparison.CurrentCulture) { int index = value.IndexOf(oldValue, comparisonType); if (index > -1) { value = value.Remove(index, oldValue.Length).Insert(index, newValue); } return value; } /// <summary> /// 替换字符串,除第一个匹配项 /// </summary> /// <param name="value">原始内容</param> /// <param name="oldValue">要替换的字符串</param> /// <param name="newValue">替换后的字符串</param> /// <returns></returns> private static string GetReplaceByNotFirst(string value, string oldValue, string newValue, StringComparison comparisonType = StringComparison.CurrentCulture) { int index = value.IndexOf(oldValue, comparisonType); if (index > -1) { value = value.Substring(0, index + 1) + (value.Substring(index + 1).Replace(oldValue, newValue)); } return value; }
保留小数点后几位
.ToString("0.0");