Jump to content

Text between: Difference between revisions

(Added solution for Action!)
Line 3,671:
Output: "BarBaz"
</pre>
 
=={{header|Yabasic}}==
{{trans|Wren}}
<lang Yabasic>// Rosetta Code problem: http://rosettacode.org/wiki/Text_between
// by Galileo, 04/2022
 
sub textBetween$(string$, start$, end$)
local s, si, e, ls
if start$ = "" and end$ = "" return "Start and end must both be non-empty strings."
if (string$ == "") return string$
if start$ = "start" then s = 1 else s = instr(string$, start$) end if
if s = 0 return ""
if start$ = "start" then si = 1 else si = s + len(start$) end if
ls = len(string$)
if end$ = "end" then e = ls + 1 else e = instr(string$, end$, si) end if
if e = 0 return right$(string$, ls - si + 1)
return mid$(string$, si, e - si)
end sub
data "Hello Rosetta Code world", "Hello", "world"
data "Hello Rosetta Code world", "start", "world"
data "Hello Rosetta Code world", "Hello", "end"
data "</div><div style=\"chinese\">???</div>", "<div style=\"chinese\">", "</div>"
data "<text>Hello <span>Rosetta Code</span> world</text><table style=\"myTable\">", "<text>", "<table>"
data "<table style=\"myTable\"><tr><td>hello world</td></tr></table>", "<table>", "</table>"
data "The quick brown fox jumps over the lazy other fox", "quick ", " fox"
data "One fish two fish red fish blue fish", "fish ", " red"
data "FooBarBazFooBuxQuux", "Foo", "Foo"
data ""
do
read text$
if text$ = "" break
print "Text: ", text$
read start$
print "Start delimiter: ", start$
read end$
print "End delimiter: ", end$
print "Output: ", textBetween$(text$, start$, end$), "\n"
loop</lang>
{{out}}
<pre>Text: Hello Rosetta Code world
Start delimiter: Hello
End delimiter: world
Output: Rosetta Code
 
Text: Hello Rosetta Code world
Start delimiter: start
End delimiter: world
Output: Hello Rosetta Code
 
Text: Hello Rosetta Code world
Start delimiter: Hello
End delimiter: end
Output: Rosetta Code world
 
Text: </div><div style="chinese">???</div>
Start delimiter: <div style="chinese">
End delimiter: </div>
Output: ???
 
Text: <text>Hello <span>Rosetta Code</span> world</text><table style="myTable">
Start delimiter: <text>
End delimiter: <table>
Output: Hello <span>Rosetta Code</span> world</text><table style="myTable">
 
Text: <table style="myTable"><tr><td>hello world</td></tr></table>
Start delimiter: <table>
End delimiter: </table>
Output:
 
Text: The quick brown fox jumps over the lazy other fox
Start delimiter: quick
End delimiter: fox
Output: brown
 
Text: One fish two fish red fish blue fish
Start delimiter: fish
End delimiter: red
Output: two fish
 
Text: FooBarBazFooBuxQuux
Start delimiter: Foo
End delimiter: Foo
Output: BarBaz
 
---Program done, press RETURN---</pre>
 
=={{header|zkl}}==
672

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.