String matching: Difference between revisions

Content added Content deleted
Line 823: Line 823:
=={{header|Lang5}}==
=={{header|Lang5}}==
<lang lang5>: bi* '_ set dip _ execute ; : bi@ dup bi* ;
<lang lang5>: bi* '_ set dip _ execute ; : bi@ dup bi* ;
: comb "" split ; : concat "" join ;
: comb "" split ; : concat "" join ; : dip swap '_ set execute _ ;
: dip swap '_ set execute _ ; : flip comb reverse concat ;
: first 0 extract swap drop ; : flip comb reverse concat ;


: contains
: contains
"comb length" bi@ swap 4 3 _roll 2 compress reshape # create a matrix.
"comb length" bi@ swap 4 3 _roll 2 compress reshape # create a matrix.
shape dup first iota swap reshape -1 transpose first -rot # position.
: concat.(*) concat ;
'concat "'concat. apply" bi* eq [1] index collapse
: concat.(*) concat ;
'concat "'concat. apply" bi* eq 1 1 compress index collapse
length if expand drop else drop 0 then ; # result.
length if expand drop else drop 0 then
extract swap drop ; # result: positon.
: end-with 'flip bi@ start-with ;
: end-with 'flip bi@ start-with ;
: start-with 'comb bi@ length rot swap iota subscript 'concat bi@ eq ;
: start-with 'comb bi@ length rot swap iota subscript 'concat bi@ eq ;


"rosettacode" "rosetta" start-with . # 1
"rosettacode" "rosetta" start-with . # 1
"rosettacode" "taco" contains . # 4
"rosettacode" "taco" contains . # 5
"rosettacode" "ocat" contains . # 0
"rosettacode" "ocat" contains . # 0
"rosettacode" "edoc" end-with . # 0</lang>
"rosettacode" "edoc" end-with . # 0
"rosettacode" "code" contains . # 7</lang>


=={{header|Liberty BASIC}}==
=={{header|Liberty BASIC}}==