1. Strtok-v2-1.e problem

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.

new topic     » topic index » view message » categorize

2. Re: Strtok-v2-1.e problem

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/

new topic     » goto parent     » topic index » view message » categorize

3. Re: Strtok-v2-1.e problem

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

new topic     » goto parent     » topic index » view message » categorize

4. Re: Strtok-v2-1.e problem

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!

new topic     » goto parent     » topic index » view message » categorize

5. Re: Strtok-v2-1.e problem

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

new topic     » goto parent     » topic index » view message » categorize

6. Re: Strtok-v2-1.e problem

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

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu