|
-
Jan 11th, 2003, 10:31 AM
#1
Thread Starter
Hyperactive Member
Split a string on certain poitions.
I'm trying to split a string on certain positions such as the following code.
VB Code:
dim catID, parID
catID = 3
parID = "1a1a11a1"
dim intX = 0 to catID
if intX = 0 then
'Grab the numbers from the first a and all numbers before it
'the one before the first a can also be a numbers like 243a
if intX = 1 then
'Go to the second a, don't grab the a but grab everything before it.
if intX = 2 then
'Go to the third a and don't grab the a but grab everything before it.
next
Please if anyone could help with this it would mean the world to me. I've been stressing over this for days , thanks alot for the help guys/girld.
Ed.
-
Jan 11th, 2003, 10:54 AM
#2
Frenzied Member
Use the SPLIT function as follows:
arString =split ("1a111a1111a111111111111","a") ->
gives:
arString(0) = "1"
arString(1) = "111"
arString(2) = "1111"
arstring(3) = "1a111a1111a111111111111"
it spilts the string u give it into parts based on a delimiter. In this example i told it 'a' was the delimiter and so it breaks it up into its component parts and stores each element in an array called arString
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Jan 11th, 2003, 11:04 AM
#3
Thread Starter
Hyperactive Member
Originally posted by Blobby
Use the SPLIT function as follows:
arString =split ("1a111a1111a111111111111","a") ->
the following should actually be
gives:
arString(0) = "1" ------------------> "1a"
arString(1) = "111" ---------------> "1a111a"
arString(2) = "1111" -------------> "1a111a1111a"
arstring(3) = "1a111a1111a111111111111"
it spilts the string u give it into parts based on a delimiter. In this example i told it 'a' was the delimiter and so it breaks it up into its component parts and stores each element in an array called arString
i was trying with the split the problem here is i need them to also grab the a's before. so for your result should be such as i fixed them on top, thank's a millin for the response, i apreciate it.
Any help would be greatfully apreciated thanks again.
Ed.
-
Jan 11th, 2003, 11:19 AM
#4
Frenzied Member
Create a form with a default textbox and a command button
providing the last character is an 'a' it will return as you want it to.
so 1a111a1111a will give:
1a
1a111a
1a111a1111a
but
1a111a1111 will give just:
1a
1a111a
so if you want the last field even tho it doesnt end in an 'a' just amend an a to the end of the input string (text1.text) if it hasnt got one
VB Code:
Private Sub Command1_Click()
Dim a As Integer
a = 0
position = 1
While a = 0
position = InStr(position, Text1.Text, "a")
If position = 0 Then
a = 1
Else
MsgBox Left(Text1.Text, position)
position = position + 1
End If
Wend
End Sub
Last edited by Blobby; Jan 11th, 2003 at 11:22 AM.
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|