开发者

How can I swap some values in a string variable and write it back with new values using Free Pascal?

开发者 https://www.devze.com 2023-03-09 05:34 出处:网络
Having read a line from a text file using ReadLn(InputFile, strVar), I need to read each character of strVar, and if it contains the letter \'E\' (for example), I want to output (write to a new file,

Having read a line from a text file using ReadLn(InputFile, strVar), I need to read each character of strVar, and if it contains the letter 'E' (for example), I want to output (write to a new file, in fact) the original variable but with the 'E' being swapped\replaced with the numeric digit '3'.

So, if '开发者_如何学PythonExample' is read from the file, I want '3xample' to be written to a new file.

How do I code the swapping in Free Pascal (I can do the writing to the file bit)? Other languages seem to have a swap function or something.

Thanks

Ted


You can use StringReplace

strVar := StringReplace(strVar, 'E', '3', [rfReplaceAll]);
0

精彩评论

暂无评论...
验证码 换一张
取 消