Last change
on this file since 6210 was
4068,
checked in by swagner, 14 years ago
|
Sorted usings and removed unused usings in entire solution (#1094)
|
File size:
1.7 KB
|
Line | |
---|
1 | using System.Collections.Generic;
|
---|
2 |
|
---|
3 | namespace HeuristicLab.Persistence.Auxiliary {
|
---|
4 | /// <summary>
|
---|
5 | /// Extension methods for the <see cref="System.String"/> class.
|
---|
6 | /// </summary>
|
---|
7 | public static class StringExtensions {
|
---|
8 |
|
---|
9 | /// <summary>
|
---|
10 | /// Enumeration over the substrings when split with a certain delimiter.
|
---|
11 | /// </summary>
|
---|
12 | /// <param name="s">The string.</param>
|
---|
13 | /// <param name="delimiter">The delimiter.</param>
|
---|
14 | /// <returns>An enumeration over the delimited substrings.</returns>
|
---|
15 | public static IEnumerable<string> EnumerateSplit(this string s, char delimiter) {
|
---|
16 | int startIdx = 0;
|
---|
17 | for (int i = 0; i < s.Length; i++) {
|
---|
18 | if (s[i] == delimiter) {
|
---|
19 | if (i > startIdx) {
|
---|
20 | yield return s.Substring(startIdx, i - startIdx);
|
---|
21 | }
|
---|
22 | startIdx = i + 1;
|
---|
23 | }
|
---|
24 | }
|
---|
25 | if (startIdx < s.Length)
|
---|
26 | yield return s.Substring(startIdx, s.Length - startIdx);
|
---|
27 | }
|
---|
28 |
|
---|
29 | /// <summary>
|
---|
30 | /// Enumeration over the substrings when split with a certain delimiter..
|
---|
31 | /// </summary>
|
---|
32 | /// <param name="s">The string.</param>
|
---|
33 | /// <param name="delimiter">The delimiter.</param>
|
---|
34 | /// <returns>An enumerator over the delimited substrings.</returns>
|
---|
35 | public static IEnumerator<string> GetSplitEnumerator(this string s, char delimiter) {
|
---|
36 | int startIdx = 0;
|
---|
37 | for (int i = 0; i < s.Length; i++) {
|
---|
38 | if (s[i] == delimiter) {
|
---|
39 | if (i > startIdx) {
|
---|
40 | yield return s.Substring(startIdx, i - startIdx);
|
---|
41 | }
|
---|
42 | startIdx = i + 1;
|
---|
43 | }
|
---|
44 | }
|
---|
45 | if (startIdx < s.Length)
|
---|
46 | yield return s.Substring(startIdx, s.Length - startIdx);
|
---|
47 | }
|
---|
48 | }
|
---|
49 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.