 |

03-01-2003, 08:11 PM
|
|
|
Splitting a string into variables?
|
Ok I found some threads that sort of touched on this, but none that really gave a straight answer. I have a string of characters and I want each of those characters to be a seperate variable. For example, say I have a string that says "Bob". I want one variable for "B", one for "o" and one for "b" So that I can deal with each seperately.
Thanks in advance
--AcidGoat
|
|

03-01-2003, 08:17 PM
|
 |
Senior Contributor
|
|
Join Date: Jun 2002
Location: Where Heaven & Hell meet
Posts: 813
|
|
Ostr is the old string
Nstr is the new string
Code:
ReDim Nstr(Len(Ostr))
For i = 1 To Len(Ostr)
Nstr(i) = Mid(Ostr, i, 1)
Next i
|
__________________
"They say the the world will end in the same way it was created. I disagree, I think it'll end without the internet" ~ Kaluriel 2001
"The edit button is mightier than the doublepost" ~ Kaluriel 2003
|

03-01-2003, 08:21 PM
|
 |
Political Coder
Retired Moderator * Guru *
|
|
Join Date: Mar 2001
Location: London, England
Posts: 8,037
|
|
Or..
Code:
Dim b() As Byte
b = StrConv(OStr, vbFromUnicode)
|
|

03-01-2003, 08:23 PM
|
 |
Senior Contributor
|
|
Join Date: Jun 2002
Location: Where Heaven & Hell meet
Posts: 813
|
|
**** you, your always one step ahead lol 
|
__________________
"They say the the world will end in the same way it was created. I disagree, I think it'll end without the internet" ~ Kaluriel 2001
"The edit button is mightier than the doublepost" ~ Kaluriel 2003
|

03-01-2003, 08:29 PM
|
|
|
Hmm... maybe I should have mentioned this: the string will always be 12 characters long. I need each character to be its own variable, appropriately named. The first character will be a variable called "char1" the second "char2" etc... Example: say the string is "goatgoatgoat" (excuse the lack of creativity  ). I want this to result: char1 = g, char2 = o, char3 = a, char4 = t, char5 = g, char6 = o, char7 = a, char8 = t, char9 = g, char10 = o, char11 = a, char12 = t.
Is this even possible?
|
|

03-01-2003, 08:41 PM
|
 |
Jedi Coder
* Expert *
|
|
Join Date: Aug 2002
Location: Abingdon, MD
Posts: 3,438
|
|
Sure, but it'll be ugly.
Code:
Dim char1 As String
Dim char2 As String
Dim char3 As String
Dim char4 As String
Dim char5 As String
Dim char6 As String
Dim char7 As String
Dim char8 As String
Dim char9 As String
Dim char10 As String
Dim char11 As String
Dim char12 As String
Dim sString As String
Dim iLp As Integer
sString = "goatgoatgoat"
Dim sChar As String
For iLp = 0 To 11
sChar = Mid$(sString, iLp, 1)
Select Case iLp
Case 0
char1 = sChar
Case 1
char2 = sChar
Case 2
char3 = sChar
Case 3
char4 = sChar
Case 4
char5 = sChar
Case 5
char6 = sChar
Case 6
char7 = sChar
Case 7
char8 = sChar
Case 8
char9 = sChar
Case 9
char10 = sChar
Case 10
char11 = sChar
Case 11
char12 = sChar
End Select
Next iLp
|
|

03-01-2003, 08:50 PM
|
|
|
|
Hmmm... I tried that code and got this: Run-time error '5': Invalid procedure call or argument. Upon hitting debug, this line was highlighted: sChar = Mid$(sString, iLp, 1)
Maybe there's somethign I'm missing, but I've never seen code like this before (I haven't been using VB for very long, sorry).
|
|

03-01-2003, 09:16 PM
|
|
|
|
After a bit of tinkering and investigating I was able to get it to work. This is what I used:
sString = "goatgoatgoat"
char1 = Mid$(sString, 1, 1)
char2 = Mid$(sString, 2, 1)
char3 = Mid$(sString, 3, 1)
char4 = Mid$(sString, 4, 1)
char5 = Mid$(sString, 5, 1)
char6 = Mid$(sString, 6, 1)
char7 = Mid$(sString, 7, 1)
char8 = Mid$(sString, 8, 1)
char9 = Mid$(sString, 9, 1)
char10 = Mid$(sString, 10, 1)
char11 = Mid$(sString, 11, 1)
char12 = Mid$(sString, 12, 1)
|
|

03-01-2003, 09:16 PM
|
 |
Senior Contributor
|
|
Join Date: Jun 2002
Location: Where Heaven & Hell meet
Posts: 813
|
|
|
iLp could be 1 to 12. You can't start a character number 0
|
__________________
"They say the the world will end in the same way it was created. I disagree, I think it'll end without the internet" ~ Kaluriel 2001
"The edit button is mightier than the doublepost" ~ Kaluriel 2003
|

03-01-2003, 11:30 PM
|
 |
Junior Contributor
|
|
Join Date: Oct 2002
Location: The Moon - Yes! Its true
Posts: 222
|
|
|
why do u want each letter to have its own variable?
isn't this EXACTLY what an array is for?
|
__________________
"...You would know zat another word for an iconographer would be 'photographer'? From the old word photus in Latation, vhich means-'
'To prance around like a pillock ordering everyone about as if you owned the place?..."
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|