vb.net - Displaying each element of array on new line -
please consider new vb.net when attempting read , reply question
i have textbox takes in list of words separated comma on same line. when button clicked string gets assigned variable text , split variable arraytext. loop on , display each element of array on new line.
my code looks follows
dim text string dim arraytext() string text = textbox1.text arraytext = text.split(",") 'every "," generates new array index, removes "," text = "" = 0 arraytext.length step 1 text = arraytext(i) & vbcrlf msgbox(text) next
when debugging error message array out of bounds, when remove newline character (vbcrlf) displays text, word word in messagebox (which using debugging) , @ end of loop kicks out same error message.
what doing wrong here, improvement suggestions?
though walther reply right, suggest utilize list(of string)
, for each...next loop.
a list more "modern" , of times preferred on array in vb.net. can utilize environment.newline
instead of vbcrlf
. i'm not sure want do, dont think using msgbox
optimal way nowadays seperated words. here simple illustration of think should :
' hold text text box. dim fulltext string = textbox1.text dim seperatedwords new list(of string) ' tolist function converts array list. seperatedwords = fulltext.split(",").tolist ' reset text re-presentation. fulltext = "" ' goes through seperated words , assign them fulltext new line. each word string in seperatedwords fulltext = fulltext & word & environment.newline next ' nowadays new list in text box. textbox1.text = fulltext
vb.net
No comments:
Post a Comment