using System.Text; using System.Text.RegularExpressions; public static class StringExtensions { public static string ReplaceFirstInstance(this string originalString, string[] findValues, string replacementPattern) { string joined = string.Join('|', findValues); string pattern = $"{joined}"; var r = new Regex(pattern, RegexOptions.IgnoreCase); string updatedString = r.Replace(originalString, replacementPattern, 1); return updatedString; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter