split function

hazejean

Well-known member
Joined
Jul 11, 2003
Messages
68
I have a text string with : in the middle
I want text left of the colon to go in one variable
I want text to right of colon to go to another variable

Thanks
 
You use the Split function of the String class to split the string into an array using a delimiter.
Code:
Dim myString As String = "leftside:rightside"
Dim parts() As String

parts = myString.Split(":")
At that point, parts(0) will contain "leftside" and parts(1) will contain "rightside".
 
Code:
Dim text As string = "Some : Text"
Dim texts() As String = text.Split(":", 2) split the text with ":" and then you can specify how many string can be returned
As the Split function an array of string, if you dont want array you will have to assign the values of the array members to your variables.
 
For i = 1 To noverbs
verb(i) = ListBox1.Items(i)
For j = 0 To 1
parts = verb(i).Split(" : ")
verbl(i) = parts(0)
verbr(i) = parts(1)
Next j
Next i
 
Well, the loop j is completely redundant. I think the problem might be that you are splitting on " : " and not ":". Try this:
Code:
For i = 1 to noverbs
  verb(i) = ListBox1.Items(i)
  parts = verb(i).Split(":") note theres no spaces
  verbl(i) = parts(0)
  verbr(i) = parts(1)
Next i
 
I really have a more complex problem than above If there is a colon in the text string.. left side goes to verbl and right side goes to verbr.
But if no colon in line , whole string goes to verbr and verbl

but dont even have split working yet.

Thanks for any ideas.
 
What exactly do you get in parts(0) when parts(1) gives an error.
Any chance you could give an example of the data you are working with?
 
This is a sample of questionaire:
Text left of : is checkbox label
Text to right of : goes to an output file if box is checked


another
 
Back
Top