Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Experts*
Posted
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".

  • *Experts*
Posted

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.

  • *Experts*
Posted
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

Posted

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.

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...