-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathStringExtensions.cs
More file actions
41 lines (35 loc) · 1.25 KB
/
StringExtensions.cs
File metadata and controls
41 lines (35 loc) · 1.25 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
38
39
40
41
using System.Collections.Generic;
using System.Linq;
namespace Semmle.Util
{
public static class StringExtensions
{
public static (string, string) Split(this string self, int index0)
{
var split = self.Split(new[] { index0 });
return (split[0], split[1]);
}
public static (string, string, string) Split(this string self, int index0, int index1)
{
var split = self.Split(new[] { index0, index1 });
return (split[0], split[1], split[2]);
}
public static (string, string, string, string) Split(this string self, int index0, int index1, int index2)
{
var split = self.Split(new[] { index0, index1, index2 });
return (split[0], split[1], split[2], split[3]);
}
private static List<string> Split(this string self, params int[] indices)
{
var ret = new List<string>();
var previousIndex = 0;
foreach (var index in indices.OrderBy(i => i))
{
ret.Add(self.Substring(previousIndex, index - previousIndex));
previousIndex = index;
}
ret.Add(self.Substring(previousIndex));
return ret;
}
}
}