如何使用c#从文本文件中读取两个字符串之间的文本?

时间:2017-01-18 13:52:14

标签: c#

我的文字档案

   Users of Yamaha:  (Total of 1 bike issued;  Total of 1 bike in use)
        bike details
        1001  Dinesh , start Fri 1/13 8:55
   Users of Hero:  (Total of 1 bike issued;  Total of 1 bike in use)
        bike details
        1002  Monika, start Fri 1/13 9:55
   Users of Honda:  (Total of 2 bike issued;  Total of 1 bike in use)
        bike details
        1003  Monikadinesh, start Fri 1/13 5:55

这里我要提取两个字符串之间的行。我想将该行附加到字符串中。我想在 用户之间提取Line。

我的提取字符串将是这样的:

//**The content lie between two users of** 
    (Total of 1 bike issued;  Total of 1 bike in use)Append it in multi array.
                bike details
                1001  Dinesh , start Fri 1/13 8:55

我不知道如何解决我的问题。请帮我解决这个问题。谢谢提前

1 个答案:

答案 0 :(得分:2)

查看String.Splithttps://msdn.microsoft.com/de-de/library/system.string.split(v=vs.110).aspx

它可能如下所示:string[] split = myString.Split(new string[] { "Users of" }, StringSplitOptions.RemoveEmptyEntries)

使用此:

删除split[0].Substring(split[0].IndexOf(":") + 3)的所有内容