www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - std.string.split("hello world", " ;")

reply bug d.com writes:
$ cat strsplit.d
import std.string;

int main(char[][] args) {
char[][] words = std.string.split("hello world", " ;");
printf("%d\n", words.length);
foreach (char[] w; words) {
printf("%.*s\n", w);
}
return 0;
}

output:
$ ./strsplit.exe
1
hello world
Oct 02 2005
parent reply Derek Parnell <derek psych.ward> writes:
On Sun, 2 Oct 2005 07:01:02 +0000 (UTC), bug d.com wrote:

 $ cat strsplit.d
 import std.string;
 
 int main(char[][] args) {
 char[][] words = std.string.split("hello world", " ;");
 printf("%d\n", words.length);
 foreach (char[] w; words) {
 printf("%.*s\n", w);
 }
 return 0;
 }
 
 output:
 $ ./strsplit.exe
 1
 hello world
What bug? Or did you mean to code ... char[][] words = std.string.split("hello world", " "); That is, the delimiter of " " rather than " ;" -- Derek Parnell Melbourne, Australia 2/10/2005 6:20:12 PM
Oct 02 2005
parent reply bug d.com writes:
What bug? Or did you mean to code ... 
 
  char[][] words = std.string.split("hello world", " "); 
 
That is, the delimiter of " " rather than " ;" 
I mean use multiple chars (or-ed) as delimiters (I think that's the intended semantics of split(str, delim), correct me if I'm wrong). char[][] words = std.string.split("hello world", "\t\r\n\v ,.;");
Oct 02 2005
parent reply JT <jtd514 ameritech.net> writes:
where do you get the idea its supposed to do that? thats not what split 
does, you specify the actual delimiter.


bug d.com wrote:
What bug? Or did you mean to code ... 

 char[][] words = std.string.split("hello world", " "); 

That is, the delimiter of " " rather than " ;" 
I mean use multiple chars (or-ed) as delimiters (I think that's the intended semantics of split(str, delim), correct me if I'm wrong). char[][] words = std.string.split("hello world", "\t\r\n\v ,.;");
Oct 02 2005
parent reply bug d.com writes:
I've thought: 
 
char[][] words = std.string.split(str);  
 
==== 
 
char[][]
words = std.string.split(str, "\t\r\n\v ");  
 
and then generalize the idea.
So is there any function provide the semantics I'm looking for? 
 
 
 
In
article <dhp5e0$bmd$1 digitaldaemon.com>, JT says... 
 
where do you get the
idea its supposed to do that? thats not what split
does, you specify the
actual delimiter.
 
 
bug d.com wrote: 
What bug? Or did you mean to code
..
 
 char[][] words = std.string.split("hello world", " ");  

That is, the delimiter of " " rather than " ;"  
I mean use multiple chars (or-ed) as delimiters (I think that's the intended semantics of split(str, delim), correct me if I'm wrong). char[][] words = std.string.split("hello world", "\t\r\n\v ,.;");
Oct 02 2005
parent reply Chris Sauls <ibisbasenji gmail.com> writes:
bug d.com wrote:
 I've thought: 
  
 char[][] words = std.string.split(str);  
  
 ==== 
  
 char[][]
 words = std.string.split(str, "\t\r\n\v ");  
  
 and then generalize the idea.
 So is there any function provide the semantics I'm looking for? 
  
Not yet, although it would be useful. -- Chris Sauls
Oct 02 2005
parent bug d.com writes:
Not yet, although it would be useful.
import std.regexp; int main(char[][] args) { char[][] words = std.regexp.split("hello world", r" |or|;"); printf("%d\n", words.length); foreach (char[] w; words) { printf("%.*s\n", w); } return 0; } $ ./strsplit 3 hello w ld
Oct 03 2005