1. Parsing with StrTok
- Posted by cklester <cklester at yahoo.com> Oct 04, 2005
- 467 views
I'm trying to do this: temp = parse( list, "\n," ) but it doesn't work with the '\n'. How do I parse on a 'newline?' I've also tried temp = parse( list, '\n' & ',' ) This does work: temp = parse( list, "," ) -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/
2. Re: Parsing with StrTok
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Oct 04, 2005
- 451 views
cklester wrote: > > I'm trying to do this: > > temp = parse( list, "\n," ) > > but it doesn't work with the '\n'. How do I parse on a 'newline?' > > I've also tried > > temp = parse( list, '\n' & ',' ) > > This does work: > > temp = parse( list, "," ) Are there perhaps some '\r's in there? Matt Lewis
3. Re: Parsing with StrTok
- Posted by cklester <cklester at yahoo.com> Oct 04, 2005
- 441 views
Matt Lewis wrote: > cklester wrote: > > I'm trying to do this: > > temp = parse( list, "\n," ) > > but it doesn't work with the '\n'. How do I parse on a 'newline?' > > I've also tried > > temp = parse( list, '\n' & ',' ) > > This does work: > > temp = parse( list, "," ) > Are there perhaps some '\r's in there? I'm actually getting an error message: ./Strtok-v2-1.e:293 in function parse() type_check failure, params is 44',' ??? -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/
4. Re: Parsing with StrTok
- Posted by "Juergen Luethje" <j.lue at gmx.de> Oct 04, 2005
- 441 views
C.K., what do you *exactly* want to achieve? ',' as well as '\n' should be recognized as delimiter in your list, right? And do you want to preserve *empty* fields between the delimiters? I.e. do you want to be "apples,oranges,,bananas" a list of 3 or of 4 items? Regards, Juergen -- Have you read a good program lately?
5. Re: Parsing with StrTok
- Posted by cklester <cklester at yahoo.com> Oct 04, 2005
- 448 views
- Last edited Oct 05, 2005
Juergen Luethje wrote: > > what do you *exactly* want to achieve? I've got a string that will be delimited by commas and/or line breaks. Kat's strtok's parse() routine seems to allow for multiple delimiters, but it doesn't seem to be working with '\n'. Got a fix? Kat? The final list needs to be in a sequence, of course. "one,two three" becomes { "one","two","three" } -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/
6. Re: Parsing with StrTok
- Posted by "Juergen Luethje" <j.lue at gmx.de> Oct 05, 2005
- 437 views
cklester wrote: > Juergen Luethje wrote: >> >> what do you *exactly* want to achieve? > > I've got a string that will be delimited by commas and/or line breaks. > Kat's strtok's parse() routine seems to allow for multiple delimiters, but > it doesn't seem to be working with '\n'. Got a fix? Kat? > > The final list needs to be in a sequence, of course. > > "one,two > three" > > becomes { "one","two","three" } OK. In order to be able to help you, I must know the answer to the other question that I asked. What do you want "one,two,,more" to become? Note the two adjacent commas. -> { "one","two","more" } or -> { "one","two","","more" } ? I don't have a fix for strtok's parse(), but I can give you another function that does the job. Regards, Juergen -- Have you read a good program lately?
7. Re: Parsing with StrTok
- Posted by cklester <cklester at yahoo.com> Oct 05, 2005
- 440 views
Juergen Luethje wrote: > cklester wrote: > > Juergen Luethje wrote: > >> what do you *exactly* want to achieve? > > I've got a string that will be delimited by commas and/or line breaks. > > Kat's strtok's parse() routine seems to allow for multiple delimiters, but > > it doesn't seem to be working with '\n'. Got a fix? Kat? > > > > The final list needs to be in a sequence, of course. > > > > "one,two > > three" > > > > becomes { "one","two","three" } > > OK. In order to be able to help you, I must know the answer to the other > question that I asked. What do you want "one,two,,more" to become? Note > the two adjacent commas. > -> { "one","two","more" } > or > -> { "one","two","","more" } The first one. Empty sequences aren't needed. -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/
8. Re: Parsing with StrTok
- Posted by "Juergen Luethje" <j.lue at gmx.de> Oct 05, 2005
- 452 views
cklester wrote: > Juergen Luethje wrote: <snip> >> What do you want "one,two,,more" to become? >> Note the two adjacent commas. >> -> { "one","two","more" } >> or >> -> { "one","two","","more" } > > The first one. Empty sequences aren't needed. Maybe it can be done faster? However, this is simple and straightforward:
-- slightly modified after code by Andy Serpa -- (posted November 2004 on EUforum) constant FALSE = 0, TRUE = not FALSE type boolean (object x) if integer(x) then return x = FALSE or x = TRUE end if return FALSE end type function parse (sequence source, sequence delimList) -- in: source : string to parse -- delimList: list of characters that are considered delimiters sequence parsed integer ptr boolean app parsed = {} ptr = 1 app = FALSE for i = 1 to length(source) do if find(source[i], delimList) then if app = TRUE then parsed = append(parsed, source[ptr..i-1]) app = FALSE ptr = i+1 else ptr += 1 end if else app = TRUE end if end for if app = TRUE then parsed = append(parsed, source[ptr..$]) end if return parsed end function -- Demo include misc.e sequence source, delimList, parsed source = "\rone,two\n,three,,\r\nfour,,," delimList = ",\r\n" parsed = parse(source, delimList) pretty_print(1, parsed, {3})
Regards, Juergen -- Have you read a good program lately?
9. Re: Parsing with StrTok
- Posted by cklester <cklester at yahoo.com> Oct 05, 2005
- 453 views
Juergen Luethje wrote: > > Maybe it can be done faster? > However, this is simple and straightforward: Beautiful, Juergen. Thanks! :) -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/