Connecting Tech Pros Worldwide Forums | Help | Site Map

Tokenizing

Craig Buchanan
Guest
 
Posts: n/a
#1: Jun 13 '06
I'm trying to extract the key/value pairs string like this:

[Status]
CurrTime = 1200
LastPlayQUpdate = 400
CurrVolume = -10
[End Status]

My first instinct is to use a regular expression to match values before and
after the '=', but there probably is a more efficient method.

Can anyone suggest a better approach?

Thanks,

Craig Buchanan



Charlie Brown
Guest
 
Posts: n/a
#2: Jun 13 '06

re: Tokenizing



Dim strPairs() As String = Split(line, "=")

You could load the text file (I guess i am assuming this is where the
data is from) line by line and extract the pairs.

Craig Buchanan wrote:[color=blue]
> I'm trying to extract the key/value pairs string like this:
>
> [Status]
> CurrTime = 1200
> LastPlayQUpdate = 400
> CurrVolume = -10
> [End Status]
>
> My first instinct is to use a regular expression to match values before and
> after the '=', but there probably is a more efficient method.
>
> Can anyone suggest a better approach?
>
> Thanks,
>
> Craig Buchanan[/color]

GhostInAK
Guest
 
Posts: n/a
#3: Jun 13 '06

re: Tokenizing


Hello Craig,

This is an INI file. Use DllImport ('Declare' keyword in VB) to import
GetPrivateProfileString from Kernel32.dll.
In fact there are several GetPrivateProfile* functions.

http://msdn.microsoft.com/library/de...filestring.asp


-Boo

[color=blue]
> I'm trying to extract the key/value pairs string like this:
>
> [Status]
> CurrTime = 1200
> LastPlayQUpdate = 400
> CurrVolume = -10
> [End Status]
> My first instinct is to use a regular expression to match values
> before and after the '=', but there probably is a more efficient
> method.
>
> Can anyone suggest a better approach?
>
> Thanks,
>
> Craig Buchanan
>[/color]


Cor Ligthert [MVP]
Guest
 
Posts: n/a
#4: Jun 13 '06

re: Tokenizing


Craig,

As alternative from Charlie,

You can just use the string.lastindex of method (although in this sampe the
standard indexoff method goes as well to) to get the starting point for a
string.substring.)

http://msdn.microsoft.com/library/de...exoftopic2.asp

http://msdn.microsoft.com/library/de...ringtopic1.asp

Alternatively you can use as well the Find and the Mid

I hope this helps,

Cor


"Craig Buchanan" <someone@microsoft.com> schreef in bericht
news:%23ZdW6rpjGHA.4748@TK2MSFTNGP04.phx.gbl...[color=blue]
> I'm trying to extract the key/value pairs string like this:
>
> [Status]
> CurrTime = 1200
> LastPlayQUpdate = 400
> CurrVolume = -10
> [End Status]
>
> My first instinct is to use a regular expression to match values before
> and after the '=', but there probably is a more efficient method.
>
> Can anyone suggest a better approach?
>
> Thanks,
>
> Craig Buchanan
>[/color]


Closed Thread


Similar Visual Basic .NET bytes