Text between: Difference between revisions

m
m (→‎{{header|Quackery}}: put output in scrolling box)
m (→‎{{header|Wren}}: Minor tidy)
 
(4 intermediate revisions by 3 users not shown)
Line 2,544:
$ "Hello Rosetta Code world" $ "Hello " $ "end" task
$ '</div><div style=\"chinese\">???</div>'
$ '<div style=\"chinese\">' $ "</div>" task
$ '<text>Hello <span>Rosetta Code</span> world</text><table style=\"myTable\">'
$ "<text>" $ "<table>" task
Line 2,550:
$ "<table>" $ "</table>" task
$ "The quick brown fox jumps over the lazy other fox"
$ "quick " $ " fox" task
$ "One fish two fish red fish blue fish"
$ "fish " $ " red" task
Line 2,593:
 
Text: "The quick brown fox jumps over the lazy other fox"
Start: "quick "
End: " fox"
Result: " brown "
 
Text: "One fish two fish red fish blue fish"
Line 2,947:
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,916:
{{trans|Kotlin}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
var textBetween = Fn.new { |str, start, end|
Line 3,995 ⟶ 4,009:
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>
 
9,482

edits