www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Bug in split?

reply mcl <mcl_member pathlink.com> writes:
std.string.split and std.string.splitlines don't seem to be stopping at the
delimiters for substrings.  

Here's an example:
char[] str1 = "A B C D";
char[][] str2 = split(str1);

Will result with str2 equal to:
"A B C D"
"B C D"
"C D"
"D"
Sep 05 2004
next sibling parent reply Andy Friesen <andy ikagames.com> writes:
mcl wrote:
 std.string.split and std.string.splitlines don't seem to be stopping at the
 delimiters for substrings.  
 
 Here's an example:
 char[] str1 = "A B C D";
 char[][] str2 = split(str1);
 
 Will result with str2 equal to:
 "A B C D"
 "B C D"
 "C D"
 "D"
This is probably because you're using printf instead of writef. :) str2's elements point inside str1, but never modifies them, so there is only ever one terminating null. -- andy
Sep 05 2004
parent mcl <mcl_member pathlink.com> writes:
In article <chh0ae$11da$1 digitaldaemon.com>, Andy Friesen says...
This is probably because you're using printf instead of writef. :)

str2's elements point inside str1, but never modifies them, so there is 
only ever one terminating null.

  -- andy
D'oh! I completely forgot about writef. From now on I'm going to switch over to streams from stdio. But first I need to get some sleep.
Sep 05 2004
prev sibling parent "Ivan Senji" <ivan.senji public.srce.hr> writes:
It works for me. Maybe there is something else wrong in your
code. Post the entire (but as small as possible) example that
has this behaviour.

"mcl" <mcl_member pathlink.com> wrote in message
news:chgvft$116p$1 digitaldaemon.com...
 std.string.split and std.string.splitlines don't seem to be stopping at
the
 delimiters for substrings.

 Here's an example:
 char[] str1 = "A B C D";
 char[][] str2 = split(str1);

 Will result with str2 equal to:
 "A B C D"
 "B C D"
 "C D"
 "D"
Sep 05 2004