Dr4ken Dr4ken - 11 months ago 59
C# Question

c# store textbox(file content) lines into array

Hey I am currently stuck. I have the following code that takes a line from a file, based on specific string and returns it, then it can be edited, and applied back to a textbox that contains the file content into the line that the string was initially taken from.

private void citationChange()
List<string> matchedList = new List<string>();

string[] linesArr = File.ReadAllLines(fileName);

//find matches
for (int a = 0; a < linesArr.Length; a++)
string s = linesArr[a];
if (s.Contains(citation))
matchedList.Add(linesArr[a]); //matched
lineBeingEdited = a;
break; //breaks the loop when a match is found

foreach (string s in matchedList)
string citationLine = s;
string[] lineData = citationLine.Split(',');
editModuleComboBox.Text = lineData[1];
selectedModuleLabel.Text = lineData[2];
moduleTitleTextBox.Text = lineData[3];
creditsTextBox.Text = lineData[4];
semesterTextBox.Text = lineData[5];
examWeightingTextBox.Text = lineData[6];
examMarkTextBox.Text = lineData[7];
testWeightingTextBox.Text = lineData[8];
testMarkTextBox.Text = lineData[9];
courseworkWeightingTextBox.Text = lineData[10];
courseworkMarkTexbox.Text = lineData[11];

How can I recreate/change this code but for it to read a textbox instead of a file?


Answer Source

Change this:

string[] linesArr = File.ReadAllLines(fileName);


string[] linesArr = theTextBox.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download