Page 1 of 3

Processing Semicolon

Posted: 16 May 2016 23:52
by tiago
Why I can't use regexreplace or trim on semicolon?

Re: Processing Semicolon

Posted: 17 May 2016 00:03
by highend
Examples where it doesn't work?

Re: Processing Semicolon

Posted: 17 May 2016 00:20
by tiago
Sure.

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";

Re: Processing Semicolon

Posted: 17 May 2016 00:26
by highend
No clue what you're talking about...

Code: Select all

    $tk = "(test);";
    $tk = regexreplace($tk, ";");
    text $tk;

    $tk = "(test);";
    $tk = trim($tk, ";");
    text $tk;
"*;(+)."
What's that, a regex pattern?

Re: Processing Semicolon

Posted: 17 May 2016 00:37
by tiago
So it seems I don't understand quoting too.

Removing quotes on "$tk" makes it work.
highend wrote:
"*;(+)."
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.

Thanks very much for your assistance, highend! 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 bet that can be done faster xD").

Re: Processing Semicolon

Posted: 17 May 2016 00:45
by tiago
I really cant take it.

Now it's not working again:

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";
Got it.
If copied from forum, it works.
Will attach it in a few secs...

Re: Processing Semicolon

Posted: 17 May 2016 00:47
by highend
Ehm, removing of quotes around $tk has what to do with this case?
This is just unnecessary quoting, that's all.

Code: Select all

$tk = regexreplace("$tk", "chr(59)", "");
This is crap. You're quoting a scripting command which makes it a string, not a command.
make regexmatches throw error messages
These are special characters. They need to be escaped in a regex pattern. A semicolon isn't one of them^^
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
Mine takes 1313 ms to produce the alphabetical sorted list "Abwurf.wav = 1<crlf>..."

Re: Processing Semicolon

Posted: 17 May 2016 00:54
by tiago
It's a trick problem. If you bother...

Go here:
http://www1.folha.uol.com.br/mercado/20 ... agem.shtml

Put the text in print preview, copy the whole page;

Paste the content on a notepad window;

Locate "(SP);" on it, copy it and use it as source for "$tk" variable at the posted script (any version).

-regexreplace and trim will not process it!

Re: Processing Semicolon

Posted: 17 May 2016 00:57
by tiago
highend wrote:Ehm, removing of quotes around $tk has what to do with this case?
This is just unnecessary quoting, that's all.
I agree.
highend wrote:Mine takes 1313 ms to produce the alphabetical sorted list "Abwurf.wav = 1<crlf>..."
How do you do the measurement???

Re: Processing Semicolon

Posted: 17 May 2016 01:03
by highend
Show screenshots of:
Notepad with the selected text that you want to copy
Your text editor after inserting the text

Re: Processing Semicolon

Posted: 17 May 2016 01:04
by highend

Code: Select all

    $start = now("msecs");

... code to execute ...

    $duration = now("msecs") - $start;
    text $duration . " msecs";


Re: Processing Semicolon

Posted: 17 May 2016 01:17
by tiago
xy ss1.png
highend wrote: Your text editor after inserting the text
What?
I insert it right into the Run Script dialogue. Once done coding, then I paste both code and processed text into plain text files.

Re: Processing Semicolon

Posted: 17 May 2016 06:42
by bdeshi
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)", "");
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";
Anyway, chr() is not needed at all. You can just do

Code: Select all

   $tk = regexreplace($tk, ";", "");
   $tk = trim($tk, ";");
This is the FIRST thing you should've tried, before all that eval(), chr() business. :maf:

Re: Processing Semicolon

Posted: 17 May 2016 10:21
by tiago
Hello, SammaySarkar!
Thanks for popping up.
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";

Code: Select all

$tk = regexreplace($tk, "chr(59)", "");
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";
Anyway, chr() is not needed at all. You can just do

Code: Select all

   $tk = regexreplace($tk, ";", "");
   $tk = trim($tk, ";");
This is the FIRST thing you should've tried, before all that eval(), chr() business. :maf:
Not so fast, pal, not so fast!
I did started with simple'r versions. As they proved to be useless on the input described above I started experimenting.
Try to use the attached zipped .txt as source, thus avoiding the complicated steps I described, and perhaps you can see for yourself.

Re: Processing Semicolon

Posted: 17 May 2016 11:28
by bdeshi
You said you want to extract the (SP); part and trim it, but since this is already a known static string, there doesn't seem much need for scripting.
How exactly do you want to process that attached text?