+ 1
How to make an action occur for each line in a string?
This is a noob question but I haven't done much in C# so far, I'm hoping to take lines from a string, google them individually then add something to the end of the line if a result returns on google. Hope that isn't too confusing, not sure how to explain it. The google part I have down, I just don't know how to use each line seperately and the text from that line.
4 ответов
+ 2
True. You can't chance elements that are part of a foreach loop. In this case you need to use a for-loop
+ 2
How are the lines separated ?
Have a look at
string[] words = s.Split(' ');
For carriage return use "\n" or "\r\n"
https://www.dotnetperls.com/split
0
Seperated by \r\n, that got them to split, thanks. Do you know how to use each array seperately in a foreach statement? I tried
foreach(string item in array)
{
item = item + " success";
Console.WriteLine(item);
}
and console writeline worked but changing the item and adding to the end of it returned an error that I couldn't use it since it's a variable in a foreach statement.
0
okay thanks.