Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_s.beg("_")
#1
Why does the following code return 0?

Macro Macro51
Code:
Copy      Help
_s="_54001"; out _s.beg("_")
#2
The seconds string starts with the UTF-8 BOM. Text editors don't display it.

Macro Macro3667
Code:
Copy      Help
out _s[0] ;;95
_s="_"; out _s[0] ;;239
#3
Thanks for your help,
Regarding this point, it is not easy to intuitively understand in QM.
It works perfectly fine in LA, with no issues as mentioned above.

Code:
Copy      Help
//.
script.setup(trayIcon: true, sleepExit: true);
//..

string s="_54001";
print.it(s.StartsWith("_"));
#4
`StartsWith` with default culture removes BOM. With ordinal culture - same as in QM.
#5
I still don’t quite understand —
where does the BOM character come from? Isn't the BOM character at the beginning of a binary file?

Below is the complete code. My original a.txt file was indeed encoded in UTF-8 with BOM, but after I changed the file to UTF-8 encoding, the code still does not work.

Macro Macro53
Code:
Copy      Help
out

str ss.getfile("$desktop$\a.txt")
foreach _s ss
,;_s.trim("_")
,if(_s.beg("_"))
,,_s.trim("_")
,,out _s
,,;some code
,,continue
,out _s
#6
`getfile` does not remove BOM.

.NET file functions remove BOM.

In QM can be used `LoadUnicodeFile`. It removes BOM.

Macro Macro3668
Code:
Copy      Help
_s.getfile("$temp$\UTF-8 no BOM")
out _s.len
_s.getfile("$temp$\UTF-8 BOM")
out _s.len
_s.LoadUnicodeFile("$temp$\UTF-8 BOM")
out _s.len
#7
I don’t understand the output of the following code. I think the final output should be as follows.
Quote:54001
15660
13420
domo:
[Image: demo.gif]


Macro Macro53
Code:
Copy      Help
out

str ss
ss.getfile("$desktop$\a.txt")
out ss.beg("_")

ss.LoadUnicodeFile("$desktop$\a.txt")
out ss.beg("_")

foreach _s ss
,if(_s.beg("_"))
,,_s.trim("_")
,,out _s
,,continue
,out _s

Macro T
Code:
Copy      Help
out

str ss=
;_54001
;15660
;13420

out ss.beg("_") ;;OK

foreach _s ss
,if(_s.beg("_"))
,,out _s.beg("_") ;;????
,,_s.trim("_")
,,out _s
,,continue
,out _s
#8
LA Code is OK:
Code:
Copy      Help
//.
script.setup(trayIcon: true, sleepExit: true);
//..


string s = """
_54001
15660
13420
"""
;

print.it(s.StartsWith("_")); //OK

foreach (var line in s.Split(new[] { "\r\n", "\n", "\r" }, StringSplitOptions.None))
{

    if (line.StartsWith("_"))
    {

        print.it(line.StartsWith("_")); // OK
        string trimmed = line.TrimStart('_');
        print.it(trimmed);
        continue;
    }

    print.it(line);
}
#9
Macro T
Code:
Copy      Help
out

str ss=
;_15660
;15660_

out ss.beg("_") ;;1
out ss.end("_") ;;1

foreach _s ss
,if(_s.beg("_") or _s.end("_"))
,,out _s ;;Why is there no output?

Macro T2
Code:
Copy      Help
out

str ss=
;_15660
;15660_

out ss.beg("_") ;;1
out ss.end("_") ;;1

ARRAY(str) as=ss

for _i 0 as.len
,if as[_i].beg("_") or as[_i].end("_")
,,out as[_i] ;;has output

The result is correct when using a for loop, but incorrect when using a foreach loop. Is this a bug?
#10
Quote:I don’t understand the output of the following code
BOM is not only in the file. Somehow it is also in the string in this code: if(_s.beg("<BOM>_")). It already was there in the first post.
#11
This is really strange.
Why would it be inside the string? I typed these characters manually.
Why is the output correct when using a for loop?  Huh
#12
Macro BOM detector
Code:
Copy      Help
_s.getclip
out _s.len

Copy a "_" from a QM code and run this QM macro. If copied from the foreach macro, it prints 6 (it means there is BOM); if from the for macro, it prints 3 (no BOM).

 
Quote:Why would it be inside the string? I typed these characters manually.
It's impossible if entire "_" was typed manually. It was copy-pasted with BOM. Then maybe you selected/replaced only the _, and the BOM survived.
#13
demo:
[Image: demo.gif]
#14
Because what in editor is displayed as "_" actually is "<BOM>_".
#15
Thanks again for your help.
I have now reimplemented all the related QM code using LA.


Forum Jump:


Users browsing this thread: 1 Guest(s)