string.split vb.net
I have a text in database which is "computer-hardware". I used that code to split
' string seperated by colons '-'
开发者_运维问答 Dim info As String = strcotegory
Dim arInfo As String() = New String(3) {}
' define which character is seperating fields
Dim splitter As Char() = {"-"c}
arInfo = info.Split(splitter)
For x As Integer = 0 To arInfo.Length - 1
Response.Write(arInfo(x) & "</br> ")
Next
but now I want to get "computer" in textbox1 and "hardware" in textbox2.
please guide me
If I understood you correctly, replace the For
loop with the following lines of code:
textbox1.Text = arInfo(0)
textbox2.Text = arInfo(1)
By the way, initializing arInfo
(... = New String(3) {}
) is not necessary, since you overwrite the value of arInfo
anyway (arInfo = ...
).
精彩评论