Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Searching for an inverted Extract function
Message
From
05/10/2000 12:38:45
 
 
To
05/10/2000 08:38:07
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00425226
Message ID:
00425383
Views:
10
Hi Marten

You could use the two functions below. GetValue() retrieves a value of an option, while SetValue() replaces the value.
Hope this helps,
Daniel

*-- Retrieve a value from a string
FUNCTION GetValue

LPARAMETER tcString, tcOption

*-- lcStr = "DRIVER={Microsoft Access Driver (*.mdb)};Dbq=c:\temp\bidon.mdb;Uid=Admin;Pwd=;"

*-- examples:
*-- GtValue(lcStr, "DBQ") = "c:\temp\bidon.mdb"
*-- GtValue(lcStr, "Uid") = "Admin"

#DEFINE ccStartChar "="
#DEFINE ccEndChar ";"

*-- add start character to tcOption if omitted
tcOption = IIF(RIGHT(ALLTRIM(tcOption),1) = ccStartChar, tcOption, tcOption+ccStartChar)

lnStartPos = ATC(tcOption, tcString)
lnLen = ATC(ccEndChar, SUBSTR(tcString, lnStartPos)) - LEN(tcOption) -1

IF lnStartPos > 0
lcRetVal = SUBSTR(tcString, lnStartPos+LEN(tcOption), lnLen)
ELSE
lcRetVal = .NULL.
ENDIF

RETURN lcRetVal

FUNCTION SetValue

LPARAMETER tcString, tcOption, tcValue

*-- lcStr = "DRIVER={Microsoft Access Driver (*.mdb)};Dbq=c:\temp\bidon.mdb;Uid=Admin;Pwd=;"

*-- examples:
*-- SetValue(lcStr, "DBQ", "c:\MyDir\My.mdb") = "DRIVER={Microsoft Access Driver (*.mdb)};Dbq=c:\MyDir\My.mdb;Uid=Admin;Pwd=;"
*-- SetValue(lcStr, "PWD", "MyPassword") = "DRIVER={Microsoft Access Driver (*.mdb)};Dbq=c:\temp\bidon.mdb;Uid=Admin;Pwd=MyPassword;"


#DEFINE ccStartChar "="
#DEFINE ccEndChar ";"

*-- add start character to tcOption if omitted
tcOption = IIF(RIGHT(ALLTRIM(tcOption),1) = ccStartChar, tcOption, tcOption+ccStartChar)

lnStartPos = ATC(tcOption, tcString)

lcCurrentOption = GtValue(tcString, tcOption)

IF lnStartPos > 0
lcRetVal = STUFF(tcString, lnStartPos+LEN(tcOption), LEN(lcCurrentOption), tcValue)
ELSE
lcRetVal = .NULL.
ENDIF

RETURN lcRetVal
Daniel
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform