-
Notifications
You must be signed in to change notification settings - Fork 0
/
StringExtensions.cs
35 lines (34 loc) · 1.09 KB
/
StringExtensions.cs
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
30
31
32
33
34
35
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace MarlinEasyConfig
{
public static class StringExtensions
{
public static string ReplaceFirst(this string text, string search, string replace)
{
int pos = text.IndexOf(search);
if (pos < 0) return text;
return text.Substring(0, pos) + replace + text.Substring(pos + search.Length);
}
public static string ReplaceAll(this string seed, string[] chars, string replacementCharacter)
{
foreach (string c in chars)
{
seed = seed.Replace(c, replacementCharacter);
}
return seed;
}
public static string EscapeQuotes(this string str)
{
return Regex.Replace(str, @"\\([\s\S])|([\""|\'])", "\\$1$2");
}
/*
public static string EscapeInnerQuotes(this string str)
{
return Regex.Replace(str, @"\\([\s\S])|([\""|\'])", "\\$1$2"); //@"(?<!^)[\""\'](?!$)"
}
*/
}
}