From 1262b280e87589a0f53c610f95364de5bfddf192 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 24 Feb 2022 00:17:04 +0300 Subject: [PATCH] Replace a foreach loop with LINQ --- src/Discord.Net.Core/Format.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Discord.Net.Core/Format.cs b/src/Discord.Net.Core/Format.cs index a5951aa73..6b753dd64 100644 --- a/src/Discord.Net.Core/Format.cs +++ b/src/Discord.Net.Core/Format.cs @@ -1,3 +1,4 @@ +using System.Linq; using System.Text; using System.Text.RegularExpressions; @@ -30,17 +31,17 @@ namespace Discord { if (language != null || text.Contains("\n")) return $"```{language ?? ""}\n{text}\n```"; - else - return $"`{text}`"; + + return $"`{text}`"; } /// Sanitizes the string, safely escaping any Markdown sequences. - public static string Sanitize(string text) - { - foreach (string unsafeChar in SensitiveCharacters) - text = text.Replace(unsafeChar, $"\\{unsafeChar}"); - return text; - } + public static string Sanitize(string text) => + SensitiveCharacters.Aggregate(text, + (current, + unsafeChar) => current.Replace(unsafeChar, + $"\\{unsafeChar}")); + /// /// Formats a string as a quote. @@ -79,7 +80,7 @@ namespace Discord return result.ToString(); } - + /// /// Formats a string as a block quote. ///