Hello,
While I'm learning the basics of Chapel, I have come across
the following case where split() seems to give an unexpected result:
proc test()
{
var a = "apple orange grape"; // OK
// var a = "apple orange g"; // NG
writeln( "a = ", a );
writeln( "a.split() = ", a.split() );
var b = a.split();
for i in 1 .. b.size {
writeln( "b[", i, "]:", b[ i ] );
}
}
test();
The above code gives
a = apple orange grape
a.split() = apple orange grape
b[1]:apple
b[2]:orange
b[3]:grape
which is my expected result. On the other hand,
if I comment the line with "OK" and uncomment the line
with "NG", then I get the following result:
a = apple orange g
a.split() = apple orange
b[1]:apple
b[2]:orange
That is, split() neglects the last "g" in the string a.
I tried other patters also, and it seems that if the last word
in a string is only a single character, then split() neglects
it for some reason.
# Also, if the string has \n at the end (e.g., a = ""apple orange g\n"),
# I get the expected result again.
Is this an expected behavior of split(), or possibly a compiler issue...?
PS. Also, I'm sorry if I'm making some big (or basic) mistake about
the usage of strings.
My best regards,
Takeshi Yamamoto
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users