hazejean Posted August 7, 2003 Posted August 7, 2003 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 Quote
*Experts* Volte Posted August 7, 2003 *Experts* Posted August 7, 2003 You use the Split function of the String class to split the string into an array using a delimiter.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". Quote
*Experts* mutant Posted August 7, 2003 *Experts* Posted August 7, 2003 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. Quote
hazejean Posted August 7, 2003 Author Posted August 7, 2003 get nothing for rightside ?? left side OK. thanks Quote
hazejean Posted August 7, 2003 Author Posted August 7, 2003 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 Quote
*Experts* Volte Posted August 7, 2003 *Experts* Posted August 7, 2003 Well, the loop 'j' is completely redundant. I think the problem might be that you are splitting on " : " and not ":". Try this:For i = 1 to noverbs verb(i) = ListBox1.Items(i) parts = verb(i).Split(":") 'note there's no spaces verbl(i) = parts(0) verbr(i) = parts(1) Next i Quote
hazejean Posted August 7, 2003 Author Posted August 7, 2003 took spaces out ....makes no difference. parts(1) causes error "index outside of range? Quote
hazejean Posted August 7, 2003 Author Posted August 7, 2003 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 don't even have split working yet. Thanks for any ideas. Quote
Administrators PlausiblyDamp Posted August 7, 2003 Administrators Posted August 7, 2003 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? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
hazejean Posted August 7, 2003 Author Posted August 7, 2003 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�s house : at another�s house bar/club : in a bar or club concert : at a concert construction site : at a construction site day care : in day care home : at home nursing home : in the resident�s nursing home outdoors : in an outdoor venue party : at a party public place : in a public place restaurant : in a restaurant school : at school store : in a store work : at work in this exapmle in parts(0) I get "work" "store" etc which is fine when parts(1) is encountered gives out of range error Quote
Leaders dynamic_sysop Posted August 7, 2003 Leaders Posted August 7, 2003 have you tried LBound & UBound? to prevent " out of range " eg: Dim x As Integer For x = LBound(parts) To UBound(parts) '/// do your stuff to parts(x) Next Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.