-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringExtensions.cs
More file actions
29 lines (27 loc) · 1.19 KB
/
StringExtensions.cs
File metadata and controls
29 lines (27 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// ############################################################################
// # Galen Lanphier #
// # https://github.com/lanphiergm/AdventOfCodeCS #
// # MIT License. See LICENSE file #
// ############################################################################
using System.Text.RegularExpressions;
namespace AdventOfCode
{
/// <summary>
/// Contains extensions of the string class
/// </summary>
internal static class StringExtensions
{
/// <summary>
/// Replaces only the first occurance of oldValue with newValue
/// </summary>
/// <param name="instance">The string to use as input</param>
/// <param name="oldValue">The old value to find</param>
/// <param name="newValue">The new value to replace with</param>
/// <returns>The modified string</returns>
public static string ReplaceOnce(this string instance, string oldValue, string newValue)
{
var regex = new Regex(Regex.Escape(oldValue));
return regex.Replace(instance, newValue, 1);
}
}
}