Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
October 02, 2005 std.string.split("hello world", " ;") | ||||
---|---|---|---|---|
| ||||
$ 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 |
October 02, 2005 Re: std.string.split("hello world", " ;") | ||||
---|---|---|---|---|
| ||||
Posted in reply to bug | 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 |
October 02, 2005 Re: std.string.split( | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | >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 ,.;");
|
October 02, 2005 Re: std.string.split( | ||||
---|---|---|---|---|
| ||||
Posted in reply to bug | 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 ,.;");
>
>
|
October 02, 2005 Re: std.string.split( | ||||
---|---|---|---|---|
| ||||
Posted in reply to JT | 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 ,.;"); >> >> >> >> |
October 03, 2005 Re: std.string.split( | ||||
---|---|---|---|---|
| ||||
Posted in reply to bug | 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
|
October 03, 2005 solved use std.regexp.split Re: std.string.split( | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Sauls | >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
|
Copyright © 1999-2021 by the D Language Foundation