On 19/09/2025 10:07, Sven Schreiber wrote:
<hansl>
string hey = "aha oho, uhu"
string s
sscanf(hey, "aha %s", s) # expected: "oho, uhu"
print s # gives "oho,"
</hansl>This function is really borrowed from the standard C library. From its man page:
s Matches a sequence of non-white-space characters; the next pointer must be a pointer to the initial element of a character array that is long enough to hold the input sequence and the ter‐ minating null byte ('\0'), which is added automatically. The in‐ put string stops at white space or at the maximum field width, whichever occurs first.so the space effectively end the string that the function catches. I guess (haven't tested) that in C you could use "%[a-z, ]" do do what you want, but it appears we have a bug that prevents this from working properly in hansl.
About the whitespace: OK, good to know where it comes from, but the question is whether we want to have this behavior at the hansl level. AFAIK, in hansl the format code %s stands for an arbitrary string, including whitespace. At least it doesn't seem to be documented.
About %[a-z, ]: Not sure that this part would really be a bug, since the documentation says you need to specify the number of chars N as well. Plus, it talks about treating the hyphen differently. Indeed, using "%[abcdedfghijklmnopqrstuvwxyz, ]" worked for me in this case (although it's a bit clumsy).
(Side remark: I could work around this whole problem by using strsub() instead, but that's not the point here.)
thanks
sven