gpt4 book ai didi

c# - 如何在 C# 中搜索多个位置的直接子字符串

转载 作者:太空宇宙 更新时间:2023-11-03 13:27:34 24 4
gpt4 key购买 nike

<分区>

我有一个字符串,我需要将其分解为多个子字符串。现在根据我的条件,在分解为子字符串时,我必须在字符串中搜索两个文本。这是我的两个文本..

  1. 1。 2 To Other Mobiles(这可能会根据子字符串中需要的条件而改变)
  2. 总计(这是子串的最后一个)

这是我的示例字符串内容

1 . 1 To Airtel Mobile
1 03/MAR/2013 16:06:31 9845070641 05:44 1.80 **
2 04/MAR/2013 10:00:29 9845096416 00:14 0.30 **
Total 25:28 9.30
1 . 2 To Other Mobiles
1 03/MAR/2013 06:41:06 9448485859 00:15 0.40 **
2 04/MAR/2013 18:57:47 9448367847 08:33 3.60 **
3 05/MAR/2013 18:57:05 9448485859 00:42 0.40 **
4 05/MAR/2013 20:13:19 9448367847 00:42 0.40 **
Total 34:33 18.00
1 . 3 To Fixed Landline
21 21/MAR/2013 11:59:35 08066000000 09:34 5.00
22 22/MAR/2013 11:31:33 08066000000 15:20 8.00
Total 01:35:23 54.00

根据这两个文本的索引,我将字符串分解为子字符串。现在根据我的条件,我必须将子字符串读取到直接文本,即 Total

但在我现在的代码中,我正在读取字符串到子字符串,直到最后一个 Total 文本。

这是我的代码:

string search1 = "1 . 2 To Other Mobiles";
string search2 = "Total";

int startPosition = currentText.IndexOf(search1);
if (startPosition >= 0)
{
startPosition += search1.Length;
int endPosition = currentText.LastIndexOf(search2);
if (endPosition > startPosition)
{
string result = currentText.Substring(startPosition, endPosition - startPosition);
}
}

简而言之,我必须搜索第一个可搜索文本并开始阅读直到第二个文本。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com