|
-
Jan 16th, 2006, 07:47 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] String parsing
Well, I'm only a few months into VB so I suck with parsing stuff. Used to PHP's preg_match(). :P
Anyway I have loaded the following string from a file:
Code:
config
{
Key1 "Value1";
Key2 "Value2";
Key3
{
"Value3";
"Value4";
};
};
And I want to load it into some soft of 2d array.
arr("Key1") = "Value1"
arr("Key2") = "Value2"
arr("Key3")(0) = "Value3"
arr("Key3")(1) = "Value4"
Ideas? Other then looping though string char at a time. lol
-
Jan 16th, 2006, 09:02 AM
#2
Re: String parsing
Can you change the format of the file or is that fixed?
-
Jan 16th, 2006, 11:13 AM
#3
Re: String parsing
This will parse out the values for you. If there will be more than one instance of a sub-key, you can split the string on "{" first to get a grouping of the subkeys.
VB Code:
Dim sFirst() As String, sSecond() As String, iCount As Integer, sTemp As String
sFirst = Split(sString, Chr$(34) & ";") 'where sString is your input.
For iCount = 0 To UBound(sFirst) - 1
sSecond = Split(sFirst(iCount), Chr$(34))
sTemp = sSecond(UBound(sSecond))
Debug.Print sTemp
Next iCount
-
Jan 16th, 2006, 02:31 PM
#4
Thread Starter
Hyperactive Member
Re: String parsing
Pino, yes.
Comintern, so im stuck playing with the string functions eh
-
Jan 16th, 2006, 02:47 PM
#5
Re: String parsing
 Originally Posted by frozen
Pino, yes.
Comintern, so im stuck playing with the string functions eh
Well, you could use regular expression, but string functions are pretty easy on this one. Check out this link if you want to get started on the RegExp object. I've just personally never used it.
-
Jan 16th, 2006, 02:57 PM
#6
Re: String parsing
That's actually quite complex, to do a proper parse of that would require some recursion I think. Either that or I'm just VERY rusty with VB.
-
Jan 27th, 2006, 10:38 AM
#7
Thread Starter
Hyperactive Member
-
Jan 27th, 2006, 11:44 AM
#8
Re: String parsing
 Originally Posted by frozen
Bump.
I Googled RegExp object model and came up with this. It should get you started. You can also check this link. The Like operator might also be of use.
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
|