Read Text file and display results in separate Labels C# Visual Studios -
i'm looking read .txt file folder exe in , display parts of text file in multiple corresponding labels or richtextbox's in form.
dummy example: text box contents: "b1.txt"
questiontitle="why did chicken cross road";
answertitle[0]="it didn't";
answertitle[1]="who";
in form i'd when hit search display following:
label 1 - question: why did chicken cross road
label 2 - answer 1: didn't
label 3 - answer 2: cares
i've seen people use streamreader , others use file.openread. i'm not sure best method ready text text file , displaying specific text file specific label or richtextbox.
any great!!
to split on string need use overload takes array of strings:
string[] lines = thetext.split(new string[] { environment.newline }, stringsplitoptions.none);
if want handle different types of line breaks in text, can use ability match more 1 string. correctly split on either type of line break, , preserve empty lines , spacing in text:
string[] lines = thetext.split(new string[] { "\r\n", "\n" }, stringsplitoptions.none);
then doing lines[0] question , lines[1] first answer , on.
Comments
Post a Comment