Click here to Skip to main content
14,693,130 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everybody, I have a little problem. I have load text looks like this:
01.09 11:43:47 Vytváří se FGDB
01.09 11:43:52 Vytváří se dataset
01.09 11:44:19 0301-B-01
01.09 11:46:38 0301-B-04
01.09 11:48:05 0301-B-05
01.09 11:49:29 0301-B-06
01.09 11:51:08 0301-B-07
01.09 11:52:29 0301-B-08
01.09 11:53:54 0301-B-09
01.09 11:55:23 0301-B-10
01.09 11:56:49 0301-B-11
01.09 11:58:15 0301-B-12
...................
and that is string, but I need string[] because a I would like to do
var lines = new string[]{"whatever", "else", "***useky"};

for (var i = 0; i < lines.Length; i++) {
    var thisLine = lines[i];
    if (i > 0 && thisLine.StartsWith("***") && thisLine.EndsWith("useky")) {
        Console.WriteLine(lines[i-1]);
    }
}

Someone doesn't know how to do it, I'll be happy for any advice. Thank you so much

What I have tried:

return new []{ myString };
but I don't want to copy the whole file into the box. I already have the file loaded in output like value1
Posted
Updated 24-Sep-20 23:42pm

As Richard says, the first thing to try is File.ReadAllLines to load the data, if it is coming direct from a text file.

If it isn't, then you need to break it yourself and there is a string.Split method which will do it:
string[] lines = myInputString.Split('\n');
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900