Parsing strings containing variable names in Delphi

I am currently writing an application in which I have a function as follows:

var a,b,c, algorithm: string begin a := some-operations-with-regular-expressions; b := some-other-operation-with-regular-expressions; c := just-similar-to-b-but-different; algorithm := IniFile.ReadString('XML Info','AlgorithmExpression', ''); //algorithm is fetched like 'http://wwww.urlhere' + a + '/' + b + '/' + c DoDownload (algorithm, true); end; 

Now, I expected a, b and c to be automatically replaced by the values โ€‹โ€‹of variables with the same name, but it seems like I'm wrong. Is there a way to get the result of an algorithm variable consisting of strings between '' and variable values?

Any suggestion (even if it requires a major redesign) would be greatly appreciated.

Thank you sphinx

+4
source share
2 answers

I did not understand what you were trying to do, but a shot is being fired.

IniFile should contain something like this:

 [XML Info] AlgorithmExpression=http://wwww.urlhere[<a>]/[<b>]/[<c>] 

and you can do something like this:

 algorithm := IniFile.ReadString('XML Info','AlgorithmExpression', ''); algorithm := StringReplace(algorithm,'[<a>]',a,[]); algorithm := StringReplace(algorithm,'[<b>]',b,[]); algorithm := StringReplace(algorithm,'[<c>]',c,[]); DoDownload (algorithm, true); 
+10
source

When it comes to formatting, Delphi also has a C-style format command:

 var output: String; begin output := Format('http://%s/%s/%s', ['this', 'that', 'otherthing']); ShowMessage(output); end; 

Shows a message:

http: // this / that / otherthing

+4
source

Source: https://habr.com/ru/post/1385150/


All Articles