heya guys
If i have a variable that is in the format of:
Luke Frost : 1234567
how can i get it so that the values before the ' :' are saved as one variable and the bit after ': ' is another variable?
Thank you in advanced
Frosty
Printable View
heya guys
If i have a variable that is in the format of:
Luke Frost : 1234567
how can i get it so that the values before the ' :' are saved as one variable and the bit after ': ' is another variable?
Thank you in advanced
Frosty
I assume it's a string. So you just use string.split(":"c)
Code:Dim myString As String = "Luke Frost : 1234567"
Dim parts As String() = myString.Split(":"c)
'Now parts(0) should hold "Luke Frost " and parts(1) holds " 1234567"
how can i then get rid of the space at the end of the 1st variable and then begining of the 2nd variable?
.Trim() or split by " : " if it's consistent.
What if I had a string like AB22913 and I need to split it into
[AB][22][9]&[13]
Would I need to put a seperator such as ":" in there for it to work or is there another way?
Putting ":" in between is the easiest solution. If you cannot put ":" then you need to write some code that will split the text based on some logic or can also use Regular Expressions.
so you want the 1st 2 characters, the next 2 characters, the next character, then the last 2 characters?
use the string.substring method
vb Code:
dim theString as string = "AB22913" dim var1 as string = theString.substring(0,2) dim var2 as string = theString.substring(2,2) dim var3 as string = theString.substring(4,1) dim var4 as string = theString.substring(5,2)
Can you be a bit clearer please. I'm a noobie.
How can I seperate the variable without using a seperator?
Never mind.
Thanks Paul!
What do you need to do with it afterwards? #7 shows you how to get it into separate variables.
i think post #8 was a reply to post #6 + a thankyou for post #7