How to make an action occur for each line in a string? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.

26th Sep 2018, 10:16 PM
Brendan Johnson (thedoctormadman)
Brendan Johnson (thedoctormadman) - avatar
4 Answers
+ 2
True. You can't chance elements that are part of a foreach loop. In this case you need to use a for-loop
27th Sep 2018, 12:53 PM
sneeze
sneeze - avatar
+ 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
27th Sep 2018, 7:30 AM
sneeze
sneeze - avatar
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.
27th Sep 2018, 12:48 PM
Brendan Johnson (thedoctormadman)
Brendan Johnson (thedoctormadman) - avatar
0
okay thanks.
27th Sep 2018, 2:01 PM
Brendan Johnson (thedoctormadman)
Brendan Johnson (thedoctormadman) - avatar