Page 1 of 1
SC: String manipulation without variables being resolved [SOLVED]
Posted: 25 Mar 2022 08:36
by Filehero
Hi,
I'm scripting a cascade of string/text manipulations where the source text is read from file.
Problem: the original text contains strings which could be XY variables (e. g. "<br>").
Question: how can I manipulate those strings leaving the var strings unresolved? Can I read the original text file into a single-quoted variable?
Well, actually I should know this after all the years - but to my shame I have to admit I dont.

Re: SC: String manipulation without variables being resolved
Posted: 25 Mar 2022 09:01
by highend
Imho this would be a bug.
readfile() shouldn't
eval parts of the text, there is
eval() for stuff like this...
You could use e.g. a powershell script to copy the contents of a file to the clipboard and use that with XY...
Code: Select all
$content = Get-Content "{your file}"
Set-Clipboard $content
Re: SC: String manipulation without variables being resolved
Posted: 25 Mar 2022 10:43
by Filehero
Hi highend,
first, thanks for the quick reply.
Yes, readfile() evals the stuff on read. I will try the powershell approach later when finding some time ....
Re: SC: String manipulation without variables being resolved
Posted: 25 Mar 2022 10:57
by highend
Code: Select all
$psFile = "%TEMP%\~getContent.ps1";
$psContent = <<<>>>
$content = Get-Content -LiteralPath "<curitem>"
Set-Clipboard $content
>>>;
$psContent = regexreplace($psContent, "^[ ]{" . strlen(regexmatches(gettoken($psContent, 1, <crlf>), "^[ ]+")) . "}");
writefile($psFile, $psContent);
run lax("powershell.exe" -ExecutionPolicy ByPass -File "$psFile"), , 2, 0;
// Now do whatever you want with <clp>;
Re: SC: String manipulation without variables being resolved
Posted: 25 Mar 2022 11:48
by Filehero
As always (and famous for) quick and sophisticated. Thanks.
Now I need to find some more time to use it ....
Re: SC: String manipulation without variables being resolved
Posted: 25 Mar 2022 17:58
by jupe
How are you testing that readfile is resolving that var? because if it is by using SC text then that is what is resolving that variable not readfile, so if your only issue is what you stated, then you can adjust <br> to another string (or disable it) so it doesn't interfere by using SC br, also alternatively if you still need to avoid using readfile for some other reason, you should be able to use runret and type to get the string, instead of clipboard contamination.
Re: SC: String manipulation without variables being resolved
Posted: 25 Mar 2022 18:18
by Filehero
Just came back from a trip with my son. While was driving his scooter I had plenty of time to think about my problem again. I think I'm onto something really stupid.
I'll do some tests later, because I guess it is not
readfile(). Thanks for the heads up for now.
Edit/update:
It's not
readfile(), it was my stupid brain.
It is not
all variables as it first seemed to be. After I wrote a lot of debug messages into a file it's left to
<br> - which is the default linebreaker in
msg(). This deserves a very loud OUCH!
Background: I'm setting a up a rather long script/function collection to automatically create (or compare existing) VSCode (and Atom) snippets for XYplorer. The first source is idh_scripting_comref.htm from XYplorer.chm (extracted with 7zip), from which the relevant sections get parsed, followed by a series of html entity replacements, followed by another series of regex-based guesses on the nature of params (strings vs. numbers/booleans), followed by .......
Somewhere down this road I obviously confused myself ...
Thanks again for help - and understanding.
