For example,
string example = "Useless info\nI want this line in it's own string or part of a string[]\nUseless info"
How do I get only the second line?
Use string splitting functions:
string[] split = example.Split('\n');
Each of the array items will be a line. Then you can access the one you want by the index.
You can use this code:
string[] text=example.split("\n");
text[1] will be the second line content.
Try this. Split to newline by using \r\n
or \n
string example = "Useless info\nI want this line in it's own string or part of a string[]\nUseless info";
string[] lines = example.Split(new string[]
{
"\r\n", "\n"
}
, StringSplitOptions.None);
foreach (var line in lines)
{
Console.WriteLine(line);
}