Using Split Method

We will always work with string manipulation. One of the method is Split method. From our CSV file, we want to split each data by enter. In most of programming language, we define enter as an \r and \n. \r means carriage return and \n means new line.

Now, we want to try splitting a line in data.txt by comma (','). So Hello, Makers! will be two lines.

string[] fileLines = fileContents.Split(',');

foreach (string line in fileLines)
    Console.WriteLine(line);

// result:
// Hello
//  Makers!

Back to our SoccerGameResult.csv, we want to separate the lines by enter (\r and \n).

string[] fileLines = fileContents.Split(new char[] {'\r', '\n'} );

foreach (string line in fileLines)
    Console.WriteLine(line);

results matching ""

    No results matching ""