替换新的 Split 扩展方法

This commit is contained in:
龙腾猫跃 committed 2026-05-14 12:28:02 +08:00
1 parent 14812561f9
commit 159f16fd57
3 files changed
+4 -4

No files matched your search

+1 -1
View File
@@ -43,7 +43,7 @@ public static class ExceptionExtensions {
if (showMultilineStacks) { if (showMultilineStacks) {
lines.Add((isInnerException ? "→ " : "") + currentEx.Message.ReplaceLineEndings("\r\n", true)); lines.Add((isInnerException ? "→ " : "") + currentEx.Message.ReplaceLineEndings("\r\n", true));
if (currentEx.GetType() != typeof(Exception)) lines.Add(" 错误类型:" + currentEx.GetType().FullName); if (currentEx.GetType() != typeof(Exception)) lines.Add(" 错误类型:" + currentEx.GetType().FullName);
var stackLines = (currentEx.StackTrace?.ReplaceLineEndings("\r", true).Split('\r') ?? []) var stackLines = (currentEx.StackTrace?.SplitLines(true) ?? [])
.Select(l => l.BeforeLast("(") + l.AfterLast(")")) .Select(l => l.BeforeLast("(") + l.AfterLast(")"))
.Distinct(); .Distinct();
lines.AddRange(stackLines); lines.AddRange(stackLines);
+2 -2
View File
@@ -184,7 +184,7 @@ public static class StringExtensions {
=> str.Contains(oldValue) ? str.Replace(oldValue, newValueGetter()) : str; => str.Contains(oldValue) ? str.Replace(oldValue, newValueGetter()) : str;
/// <summary> /// <summary>
/// 将字符串中的换行符统一替换为指定字符。 /// 将字符串中的换行符统一替换为指定字符串。
/// 若指定了 <paramref name="mergeMultiple"/>,会将多个连续换行符仅替换为一个目标内容。 /// 若指定了 <paramref name="mergeMultiple"/>,会将多个连续换行符仅替换为一个目标内容。
/// </summary> /// </summary>
public static string ReplaceLineEndings(this string input, string newValue, bool mergeMultiple = false) public static string ReplaceLineEndings(this string input, string newValue, bool mergeMultiple = false)
@@ -196,7 +196,7 @@ public static class StringExtensions {
/// 将字符串分割为多行。 /// 将字符串分割为多行。
/// </summary> /// </summary>
public static string[] SplitLines(this string input, bool skipEmptyLines = false) public static string[] SplitLines(this string input, bool skipEmptyLines = false)
=> input.ReplaceLineEndings("\n").Split(['\n'], skipEmptyLines ? StringSplitOptions.RemoveEmptyEntries : StringSplitOptions.None); => input.ReplaceLineEndings("\n").Split('\n', skipEmptyLines);
#endregion #endregion
+1 -1
View File
@@ -215,7 +215,7 @@ public class BaseLogger {
string prefix = GetLogPrefix(level, filePath); string prefix = GetLogPrefix(level, filePath);
if (string.IsNullOrEmpty(text)) return prefix; if (string.IsNullOrEmpty(text)) return prefix;
return text return text
.ReplaceLineEndings("\n", mergeMultiple: true).Split(['\n'], StringSplitOptions.RemoveEmptyEntries) .ReplaceLineEndings("\n", mergeMultiple: true).Split('\n', true)
.Select(t => prefix + t) .Select(t => prefix + t)
.Join("\r\n"); .Join("\r\n");
} }