Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Searching for an inverted Extract function
Message
De
05/10/2000 12:38:45
 
 
À
05/10/2000 08:38:07
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00425226
Message ID:
00425383
Vues:
11
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform