Text between: Difference between revisions

Added Easylang
(Added Easylang)
 
(3 intermediate revisions by 3 users not shown)
Line 1,037:
Readln;
end.</syntaxhighlight>
=={{header|EasyLang}}==
<syntaxhighlight>
func$ txtbetween str$ start$ ende$ .
s = 1
if start$ <> "start"
s = strpos str$ start$
if s = 0
return ""
.
s += len start$
.
str$ = substr str$ s len str$
e = len str$
if ende$ <> "end"
e = strpos str$ ende$
if e = 0
return str$
.
e -= 1
.
return substr str$ 1 e
.
func$ q s$ .
return "\"" & s$ & "\""
.
texts$[] = [ "Hello Rosetta Code world" "Hello Rosetta Code world" "Hello Rosetta Code world" "</div><div style=\"chinese\">你好嗎</div>" "<text>Hello <span>Rosetta Code</span> world</text><table style=\"myTable\">" "<table style=\"myTable\"><tr><td>hello world</td></tr></table>" "The quick brown fox jumps over the lazy other fox" "One fish two fish red fish blue fish" "FooBarBazFooBuxQuux" ]
starts$[] = [ "Hello " "start" "Hello " "<div style=\"chinese\">" "<text>" "<table>" "quick " "fish " "Foo" ]
ends$[] = [ " world" " world" "end" "</div>" "<table>" "</table>" " fox" " red" "Foo" ]
for i to len texts$[]
print q texts$[i]
print q starts$[i] & " : " & q ends$[i]
print q txtbetween texts$[i] starts$[i] ends$[i]
print ""
.
</syntaxhighlight>
{{out}}
<pre>
"Hello Rosetta Code world"
"Hello " : " world"
"Rosetta Code"
 
"Hello Rosetta Code world"
"start" : " world"
"Hello Rosetta Code"
 
"Hello Rosetta Code world"
"Hello " : "end"
"Rosetta Code world"
 
"</div><div style="chinese">你好嗎</div>"
"<div style="chinese">" : "</div>"
"你好嗎"
 
"<text>Hello <span>Rosetta Code</span> world</text><table style="myTable">"
"<text>" : "<table>"
"Hello <span>Rosetta Code</span> world</text><table style="myTable">"
 
"<table style="myTable"><tr><td>hello world</td></tr></table>"
"<table>" : "</table>"
""
 
"The quick brown fox jumps over the lazy other fox"
"quick " : " fox"
"brown"
 
"One fish two fish red fish blue fish"
"fish " : " red"
"two fish"
 
"FooBarBazFooBuxQuux"
"Foo" : "Foo"
"BarBaz"
</pre>
 
=={{header|Factor}}==
<syntaxhighlight lang="factor">USING: combinators formatting kernel locals math
Line 1,128 ⟶ 1,202:
Output: "BarBaz"
</pre>
 
 
=={{header|FreeBASIC}}==
Line 2,947 ⟶ 3,020:
Output = "Rosetta Code world"
</pre>
 
=={{header|RPL}}==
{{works with|HP|48G}}
« → start end
« '''CASE'''
start "start" == '''THEN''' 1 '''END'''
DUP start POS '''THEN''' LASTARG start SIZE + '''END'''
DUP SIZE 1 +
'''END'''
OVER SIZE SUB
1 OVER end POS 1 -
'''IF''' DUP 0 < end "end" == OR '''THEN''' DROP OVER SIZE '''END'''
SUB
» » '<span style="color:blue">BTWN</span>' STO <span style="color:grey">''@ ( "text" "start" "end" -- "text_between" )''</span>
 
=={{header|Ruby}}==
Line 3,902 ⟶ 3,989:
{{trans|Kotlin}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
var textBetween = Fn.new { |str, start, end|
Line 3,995 ⟶ 4,082:
End delimiter: "Foo"
Output: "BarBaz"
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang "XPL0">include xpllib; \for StrFind, StrLen, Print
 
proc TextBetween(Str, StartStr, EndStr);
char Str, StartStr, EndStr;
int EndInx, I, Addr;
[if StrFind(StartStr, "start") = 0 then \another delimiter is given
[Addr:= StrFind(Str, StartStr);
if Addr # 0 then \if delimiter found then
Str:= Addr + StrLen(StartStr) \ start output string after it
else Str:= Str + StrLen(Str);
];
EndInx:= StrLen(Str) - 1;
if StrFind(EndStr, "end") = 0 then \another delimiter is given
[Addr:= StrFind(Str, EndStr);
if Addr # 0 then \if delimiter found then
EndInx:= Addr - Str - 1; \ end output string before it
];
ChOut(0, ^");
for I:= 0 to EndInx do
ChOut(0, Str(I));
ChOut(0, ^"); CrLf(0);
];
 
int Texts, Starts, Ends, I;
[Texts:= [
"Hello Rosetta Code world",
"Hello Rosetta Code world",
"Hello Rosetta Code world",
"</div><div style=^"chinese^">你好嗎</div>",
"<text>Hello <span>Rosetta Code</span> world</text><table style=^"myTable^">",
"<table style=^"myTable^"><tr><td>hello world</td></tr></table>",
"The quick brown fox jumps over the lazy other fox",
"One fish two fish red fish blue fish",
"FooBarBazFooBuxQuux"];
Starts:= [
"Hello ", "start", "Hello ", "<div style=^"chinese^">",
"<text>", "<table>", "quick ", "fish ", "Foo"];
Ends:= [
" world", " world", "end", "</div>",
"<table>", "</table>", " fox", " red", "Foo"];
for I:= 0 to 9-1 do
[Print("Example %d: ", I+1);
TextBetween(Texts(I), Starts(I), Ends(I));
];
]</syntaxhighlight>
{{out}}
<pre>
Example 1: "Rosetta Code"
Example 2: "Hello Rosetta Code"
Example 3: "Rosetta Code world"
Example 4: "你好嗎"
Example 5: "Hello <span>Rosetta Code</span> world</text><table style="myTable">"
Example 6: ""
Example 7: "brown"
Example 8: "two fish"
Example 9: "BarBaz"
</pre>
 
2,083

edits