Processing Semicolon
Posted: 16 May 2016 23:52
Why I can't use regexreplace or trim on semicolon?
Forum for XYplorer Users and Developers
https://www.xyplorer.com/xyfc/
Code: Select all
$tk = "(test);";
// step;
$tk = regexreplace("$tk", "chr(59)", ""); //otherwise regexmatches will bitch...
$tk = trim("$tk", eval("chr(59)")); //otherwise regexmatches will bitch...
$tk = trim("$tk", "*;(+)."); //otherwise regexmatches will bitch...
text "no semicolon here?<crlf>$tk";Code: Select all
$tk = "(test);";
$tk = regexreplace($tk, ";");
text $tk;
$tk = "(test);";
$tk = trim($tk, ";");
text $tk;
What's that, a regex pattern?"*;(+)."
No. Those characters, perhaps more, if present on input make regexmatches throw error messages for each time they happen on a loop. Anyway I'm considering asking a silent mode for cases like these.highend wrote:What's that, a regex pattern?"*;(+)."
Code: Select all
$tk = "(te);";
step;
$tk = regexreplace($tk, "chr(59)", ""); //otherwise regexmatches will bitch...
$tk = trim($tk, eval("chr(59)")); //otherwise regexmatches will bitch...
$tk = trim("$tk", "*;(+)."); //otherwise regexmatches will bitch...
text "no semicolon here?<crlf>$tk";Code: Select all
$tk = regexreplace("$tk", "chr(59)", "");
These are special characters. They need to be escaped in a regex pattern. A semicolon isn't one of them^^make regexmatches throw error messages
Mine takes 1313 ms to produce the alphabetical sorted list "Abwurf.wav = 1<crlf>..."Soon I'll post the entire script on a new post per your instructions so you can check what improvements can be made, as you suggested on the thanks thread
I agree.highend wrote:Ehm, removing of quotes around $tk has what to do with this case?
This is just unnecessary quoting, that's all.
How do you do the measurement???highend wrote:Mine takes 1313 ms to produce the alphabetical sorted list "Abwurf.wav = 1<crlf>..."
Code: Select all
$start = now("msecs");
... code to execute ...
$duration = now("msecs") - $start;
text $duration . " msecs";
What?highend wrote: Your text editor after inserting the text
tiago wrote:Code: Select all
$tk = "(te);"; step; $tk = regexreplace($tk, "chr(59)", ""); //otherwise regexmatches will bitch... $tk = trim($tk, eval("chr(59)")); //otherwise regexmatches will bitch... $tk = trim("$tk", "*;(+)."); //otherwise regexmatches will bitch... text "no semicolon here?<crlf>$tk";
Code: Select all
$tk = regexreplace($tk, "chr(59)", "");Code: Select all
$tk = regexreplace($tk, ";", "");
$tk = trim($tk, ";");Not so fast, pal, not so fast!SammaySarkar wrote:tiago wrote:Code: Select all
$tk = "(te);"; step; $tk = regexreplace($tk, "chr(59)", ""); //otherwise regexmatches will bitch... $tk = trim($tk, eval("chr(59)")); //otherwise regexmatches will bitch... $tk = trim("$tk", "*;(+)."); //otherwise regexmatches will bitch... text "no semicolon here?<crlf>$tk";What you're trying to do here is asking the script to match the string "chr(59)" in $tk. This could've worked if $tk = "I have chr(59) within me"; . You should not quote function calls when you want to use their return. Use them like this: $v = "prefix" . function() . "suffix";Code: Select all
$tk = regexreplace($tk, "chr(59)", "");
Anyway, chr() is not needed at all. You can just doThis is the FIRST thing you should've tried, before all that eval(), chr() business.Code: Select all
$tk = regexreplace($tk, ";", ""); $tk = trim($tk, ";");