Hi I used this in a project, maybe someone finds it useful too:
Code: Select all
;{ ==========================================================================
;| ReplaceEnvVar(text$)
;| Returns the string text$ where all strings pointing to environment
;| variables, e.g.(%windir%) are replaced by their content
;} ==========================================================================
Procedure.s ReplaceEnvVar(text$)
;*****Checks text$ if it contains %sometext% and replaces it with the
; content of the environment variable sometext
count.b = CountString(text$,"%")
result$ = text$
If count > 0
For i.b = 1 To count ;go through each part of the string surrounded by "%"
If FindString(text$,"%",1)<>0
part$ = Left(text$,FindString(text$,"%",1)-1)
EndIf
text$ = Right(text$,Len(text$)-Len(part$)-1)
If (i<>1) And (part$<>"") And (GetEnvironmentVariable(part$)<>"")
;replace found stuff by content of environment variable
result$ = ReplaceString(result$,"%"+part$+"%",GetEnvironmentVariable(part$))
EndIf
Next
EndIf
ProcedureReturn result$
EndProcedure
Code: Select all
app$ = ReplaceEnvVar("%windir%\notepad.exe")
; app$ will be e.g. "c:\windows\notepad.exe"