1. split() function (like perl's) - Reply

-- split.ex
-- j.babor at gns.cri.nz
-- 98-07-08

function split(integer c, sequence s)
    -- split string s using c as de-limiter
    sequence os
    integer i,j,inword
    os={}
    inword=0
    j=1
    while j<=length(s) do
        if inword then
            if s[j]=c then
                os=append(os,s[i..j-1])
                inword=0
            end if
        elsif s[j]!=c then
            i=j
            inword=1
        end if
        j=j+1
    end while
    if inword then os=append(os,s[i..j-1]) end if
    return os
end function

? split(' ',"")
? split(' ',"  ")
? split(' ',"Viva Euphoria !")
? split(' '," Viva Euphoria ! ")

new topic     » topic index » view message » categorize

2. Re: split() function (like perl's) - Reply

While I did not test either split solution offered yet, it seems that Ralf
has the better idea. The de-limiter may not be an integer. It may be, as is
common, a quote-comma-qoute combination as in an exported data file or a
period-space combination as in a string that was a series of sentences.

Although, I will have to admit that I do not know the behavior of the PERL
Split function.

JIRI:
>function split(integer c, sequence s)

RALF:
function split (object x, sequence s)


 Joe Phillips, Assistant Director
 Information Technology Services
 Texas Wesleyan University     817-531-4284

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

3. Re: split() function (like perl's) - Reply

Joe, I am not an IT person, I am an engineer and I usually read the specs.
Jiri

-----Original Message-----
From: Joe Phillips <bubba at TXWES.EDU>
To: EUPHORIA at cwisserver1.mcs.muohio.edu
<EUPHORIA at cwisserver1.mcs.muohio.edu>
Date: Thursday, July 09, 1998 2:53 AM
Subject: Re: split() function (like perl's) - Reply


>While I did not test either split solution offered yet, it seems that Ralf
>has the better idea. The de-limiter may not be an integer. It may be, as is
>common, a quote-comma-qoute combination as in an exported data file or a
>period-space combination as in a string that was a series of sentences.
>
>Although, I will have to admit that I do not know the behavior of the PERL
>Split function.
>
>JIRI:
>>function split(integer c, sequence s)
>
>RALF:
>function split (object x, sequence s)
>
>
> Joe Phillips, Assistant Director
> Information Technology Services
> Texas Wesleyan University     817-531-4284
>

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

4. Re: split() function (like perl's) - Reply

>While I did not test either split solution offered yet, it seems that Ralf
>has the better idea. The de-limiter may not be an integer. It may be, as is
>common, a quote-comma-qoute combination as in an exported data file or a
>period-space combination as in a string that was a series of sentences.


Those are two different things though..
split (". ", "Sentence 1. Sentence 2")

Will return {"Sentence 1. Sentence 2"}

Because it still compares ". " with every element of "Sentence 1.Sentence 2"
To split them in such case, would be: "Sentence 1" & {". "} & "Sentence 2"

Also, I made a (very common) mistake to assume compare returns true when
they are equal.. so here is the split () and split_match (). Tested and with
a short example. They're attached.

You should be able to get documentation from the comment by using NiceForm
/D
However, I didn't get it to work..

Ralf



begin 666 Splits.e
M("AN:65U=V5N0'AS-&%L;"YN;"D-"BTM(%5S92!.:6-E1F]R;2 O9"!S<&QI
M(&$@8V]S="!O9B Q,S S-#(S,#0Y,S0S,R!54RX@) T*#0IF=6YC=&EO;B!S
M<&QI=" H;V)J96-T('@L('-E<75E;F-E(',I#0H@("TM+R!5<V%G93H@<R ]
M('-P;&ET("AD96QI;6ET97(L('-E<75E;F-E*0T*(" M+2\@5&AE('-E<75E
M('1H92!D96QI;6ET97(-"B @+2TO(%1H92!D96QI;6ET97(@;V)J96-T(&ES
M90T*(" M+2\@06QL('!I96-E<R!A<F4@<F5T=7)N960@:6X@;VYE('-E<75E
M;F-E#0H-"B @<V5Q=65N8V4@<F5T#0H@(&EN=&5G97(@<&]S+"!P<F5V#0H-
M"B @<F5T(#T@>WT-"B @<')E=B ](#$-"B @<&]S(#T@9FEN9" H>"QS*0T*
M("!W:&EL92!P;W,@9&\-"B @("!R970@/2!A<'!E;F0H<F5T+"!S6W!R978N
M+G!O<UTI#0H@(" @<')E=B ]('!O<R K(#$-"B @("!P;W,@/2!F:6YD*'@L
M('-;<')E=BXN;&5N9W1H*',I72D-"B @96YD('=H:6QE#0H-"B @<F5T=7)N
M;@T*#0IF=6YC=&EO;B!S<&QI=%]M871C:" H;V)J96-T('@L('-E<75E;F-E
M(',I#0H@("TM+R!5<V%G93H@<R ]('-P;&ET7VUA=&-H("AD96QI;6ET97(L
M('-E<75E;F-E*0T*(" M+2\@5&AE('-E<75E;F-E("AS96-O;F0@87)G*2!W
M:6QL(&)E(&1I=FED960@:6X@<&EE8V5S(&)Y('1H92!D96QI;6ET97(-"B @
M;GD@<V5C=&EO;B!O9B!T:&4@<V5Q=65N8V4-"B @+2TO($%L;"!P:65C97,@
M= T*("!I;G1E9V5R('!O<RP@<')E=@T*#0H@(')E=" ]('M]#0H@('!R978@
M/2 Q(" @(" -"B @:68@871O;2AX*2!T:&5N('@@/2![>'T@96YD(&EF#0H@
M('!O<R ](&UA=&-H("AX+',I#0H@('=H:6QE('!O<R!D;PT*(" @(')E=" ]
M(&%P<&5N9"AR970L('-;<')E=BXN<&]S72D-"B @("!P<F5V(#T@<&]S("L@
M;&5N9W1H*'@I#0H@(" @<&]S(#T@9FEN9"AX+"!S6W!R978N+FQE;F=T:"AS
C978N+FQE;F=T:"AS*5TI#0IE;F0@9G5N8W1I;VX-"@T*#0H`
`
end

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

Search



Quick Links

User menu

Not signed in.

Misc Menu