|
发表于 2020-3-5 11:26:53
|
显示全部楼层
河北省唐山市
- private static IEnumerable<string> AllBetweenImpl(this string input, string firstEnclosure, string secondEnclosure, StringComparison comparisonType)
- {
- int firstEnclosureIndex = input.IndexOf(firstEnclosure, comparisonType);
- while (firstEnclosureIndex != -1 && firstEnclosureIndex + firstEnclosure.Length < input.Length)
- {
- int firstAdjustedIndex = firstEnclosureIndex + firstEnclosure.Length;
- int secondEnclosureIndex = input.IndexOf(secondEnclosure, firstAdjustedIndex, comparisonType);
- if (secondEnclosureIndex == -1)
- {
- break;
- }
- else
- {
- int length = secondEnclosureIndex - firstAdjustedIndex;
- string substring = input.Substring(firstAdjustedIndex, length);
- yield return substring;
- firstEnclosureIndex = input.IndexOf(firstEnclosure, secondEnclosureIndex + secondEnclosure.Length);
- }
- }
- }
复制代码 |
|