1. Strtok-v2-1.e problem
- Posted by Haflidi Asgrimsson <haflidi at prokaria.com> Mar 31, 2005
- 499 views
I'm parsing stings such as "1__2_3_4_5". I'm using Strtok-v2-1.e and what I want is a sequence like {"1","","2","4","5"}. The parse function of Strtok-v2-1.e gives me {"1","2","4","5"}. It splits the parse string into atoms so "__" gives the same as '_'. There doesn't seem to be any substring function in the standard library so I'm kind of stranded on this simple issue. Does anyone have a idea how to do this without writing a lot of code.
2. Re: Strtok-v2-1.e problem
- Posted by cklester <cklester at yahoo.com> Mar 31, 2005
- 501 views
Haflidi Asgrimsson wrote: > > I'm parsing stings such as "1__2_3_4_5". I'm using Strtok-v2-1.e and what I > want is > a sequence like {"1","","2","4","5"}. > The parse function of Strtok-v2-1.e gives me {"1","2","4","5"}. It splits the > parse > string into atoms so "__" gives the same as '_'. > There doesn't seem to be any substring function in the standard library so I'm > kind > of stranded on this simple issue. > Does anyone have a idea how to do this without writing a lot of code. Look at Michael Raley's "Parse with Keep" library... http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=parse+with+keep -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/
3. Re: Strtok-v2-1.e problem
- Posted by "Kat" <gertie at visionsix.com> Mar 31, 2005
- 498 views
- Last edited Apr 01, 2005
On 31 Mar 2005, at 9:08, cklester wrote: > > > posted by: cklester <cklester at yahoo.com> > > Haflidi Asgrimsson wrote: > > > > I'm parsing stings such as "1__2_3_4_5". I'm using Strtok-v2-1.e and what I > > want is a sequence like {"1","","2","4","5"}. The parse function of > > Strtok-v2-1.e gives me {"1","2","4","5"}. It splits the parse string into > > atoms so "__" gives the same as '_'. There doesn't seem to be any substring > > function in the standard library so I'm kind of stranded on this simple > > issue. > > Does anyone have a idea how to do this without writing a lot of code. > > Look at Michael Raley's "Parse with Keep" library... > > > http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&key > words=parse+with+keep That would give him {"1","","","2","","4","","5"} You can't very well ask to toss the first delimiter and keep the remaining delimiter in your example. But anyhow, from the html doc for strtok: New in v2.1 is "k" for keeping the separators in the parsed nested sequence, and "i" for case insensitivity in comparing alphabetic strings (see the last 2 examples). You can use "k" and "i" at the same time. parse("nick!ident at a.net",{"k","!@"}) = {"nick","!","ident","@","a.net"} Kat Kat
4. Re: Strtok-v2-1.e problem
- Posted by Haflidi Asgrimsson <haflidi at prokaria.com> Apr 01, 2005
- 473 views
include Strtok-v2-1.e sequence s s = parse("1__2_3_4_5",{"k","_"}) puts(1,s[1]) gives 1__2_3_4_5 :p include kparse.e sequence s s = Kparse("1__2_3_4_5","_") for i = 1 to length(s) do puts(1,s[i] & ",") end for gives 1,,2,3,4,5, thanx!
5. Re: Strtok-v2-1.e problem
- Posted by "Kat" <gertie at visionsix.com> Apr 01, 2005
- 486 views
On 1 Apr 2005, at 3:29, Haflidi Asgrimsson wrote: > > > posted by: Haflidi Asgrimsson <haflidi at prokaria.com> > > include Strtok-v2-1.e > sequence s > s = parse("1__2_3_4_5",{"k","_"}) > puts(1,s[1]) > > gives 1__2_3_4_5 > :p Use '_' There is no "_" in s above, so the whole string was returned. Kat
6. Re: Strtok-v2-1.e problem
- Posted by Michael Raley <thinkways at yahoo.com> Apr 01, 2005
- 495 views
- Last edited Apr 02, 2005
Haflidi Asgrimsson wrote: > > include Strtok-v2-1.e > sequence s > s = parse("1__2_3_4_5",{"k","_"}) > puts(1,s[1]) > > gives 1__2_3_4_5 > :p > > > include kparse.e > sequence s > s = Kparse("1__2_3_4_5","_") > for i = 1 to length(s) do > puts(1,s[i] & ",") > end for > > gives 1,,2,3,4,5, > > thanx! > It's a differnt abstraction. Single charector delimiters only. Kparse evaluates the arguement "_" and '_' the same If you pass "^_" it bookmarks each delimiter position concurrently. Kparse2(sequence,"^_") will evaluate the first delimiter then each list element will be broken down by the second delimiter I haven't worked out a recursive routine yet to handle more than 2. s= "Joe^Doe|123456^F|NO CHANGE" Kparse(s,"|^") gives "Joe","Doe","123456","F","NO CHANGE" Kparse2(s,"|^") gives {"Joe","Doe"},{"123456","F"},{"NO CHANGE"} Kparse2(s,{ "|_><,\" ,"!@#$%^*" } ) is also valid