Home All Groups Group Topic Archive Search About
Author
13 Jun 2006 3:39 AM
Craig Buchanan
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

Author
13 Jun 2006 3:58 AM
Charlie Brown
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:
Show quoteHide quote
> 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
Author
13 Jun 2006 5:30 AM
GhostInAK
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/default.asp?url=/library/en-us/sysinfo/base/getprivateprofilestring.asp


-Boo


Show quoteHide quote
> 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
>
Author
13 Jun 2006 5:39 AM
Cor Ligthert [MVP]
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/default.asp?url=/library/en-us/cpref/html/frlrfsystemstringclasslastindexoftopic2.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemstringclasssubstringtopic1.asp

Alternatively you can use as well the Find and the Mid

I hope this helps,

Cor


Show quoteHide quote
"Craig Buchanan" <some***@microsoft.com> schreef in bericht
news:%23ZdW6rpjGHA.4748@TK2MSFTNGP04.phx.gbl...
> 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
>