c# - Open text file, loop through contents and check against -
so have generic number check trying implement:
public static bool isnumbervalid(string number) { }
and want read contents of textfile (only contains numbers) , check each line number , verify valid number using isnumbervalid
. want output results new textfile, got far:
private void button2_click(object sender, eventargs e) { int size = -1; dialogresult result = openfiledialog1.showdialog(); // show dialog. if (result == dialogresult.ok) // test result. { string file = openfiledialog1.filename; try { string text = file.readalltext(file); size = text.length; using (stringreader reader = new stringreader(text)) { foreach (int number in text) { // check against isnumbervalid // write results new textfile } } } catch (ioexception) { } } }
kind of stuck here if can help?
the textfile contains several numbers in list:
4564
4565
4455
etc.
the new textfile want write numbers true or false appended end:
4564 true
you try keep pattern following...
private void button1_click(object sender, eventargs e) { dialogresult result = openfiledialog1.showdialog(); // show dialog. if (result == dialogresult.ok) // test result. { string file = openfiledialog1.filename; try { using (var reader = new streamreader(file)) { using (var writer = new streamwriter("results.txt")) { string currentnumber; while ((currentnumber = reader.readline()) != null) { if (isnumbervalid(currentnumber)) writer.writeline(string.format("{0} true", currentnumber)); } } } } catch (ioexception) { } } } public bool isnumbervalid(string number) { //whatever code use check number }
Comments
Post a Comment