|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
TokenizingI'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 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 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 > 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 >
Function Vs. Sub Procedure
Marshal Structure containing arrays to function in DLL OOP object instance assignment in sub new() Final Post of the day VB.NET: RasDial + CallBacks + throwing events = frozen UI? Loopin trough colors Is there a Function and Function Argument generic self-reference? Linking childform to Main Form in VB6 A Question About Regular Expressions and Capture Setting the Title property in a Windows File ... |
|||||||||||||||||||||||