I am trying to transfer values from each line of a multi line text box into either a string array or a multidimensional array. I also have 3 multi-line text boxes which need to put into the same array. Below is one of the methods I have been trying:
ParkingTimes[0] = tbxtimeLimitS1.Text;
for (int i = 1; i <= 10; i++)
ParkingTimes[i] = tbxparkingTimesS1.Lines;
ParkingTimes[11] = tbxtimeLimitS2.Lines;
for (int x = 0; x <= 10; x++)
for (int i = 12; i <= 21; i++)
ParkingTimes[i] = tbxparkingTimesS2.Lines;
ParkingTimes[11] = tbxtimeLimitS2.Lines[0];
for (int x = 0; x <= 10; x++)
for (int i = 23; i <= 32; i++)
ParkingTimes[i] = tbxparkingTimesS3.Lines;
What am I doing wrong? Is there a better way to accomplish this?
You can simply do
string[] allLines = textbox.Text.Split('\n');
This will split each line and store the results in the appropriate index in the array. You can then iterate over them like so:
foreach (string text in allLines)
{
//do whatever with text
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With