forked from sarbian/ModuleManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringExtensions.cs
More file actions
37 lines (31 loc) · 1.04 KB
/
Copy pathStringExtensions.cs
File metadata and controls
37 lines (31 loc) · 1.04 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
30
31
32
33
34
35
36
37
using System;
using System.Text.RegularExpressions;
namespace ModuleManager.Extensions
{
public static class StringExtensions
{
public static bool IsBracketBalanced(this string s)
{
int level = 0;
foreach (char c in s)
{
if (c == '[') level++;
else if (c == ']') level--;
if (level < 0) return false;
}
return level == 0;
}
private static readonly Regex whitespaceRegex = new Regex(@"\s+");
public static string RemoveWS(this string withWhite)
{
return whitespaceRegex.Replace(withWhite, "");
}
public static bool Contains(this string str, string value, out int index)
{
if (str == null) throw new ArgumentNullException(nameof(str));
if (value == null) throw new ArgumentNullException(nameof(value));
index = str.IndexOf(value, StringComparison.CurrentCultureIgnoreCase);
return index != -1;
}
}
}