Jump to content

Text between: Difference between revisions

Scala added.
(Scala added.)
Line 2,282:
</lang>
 
=={{header|Sidef}}==
<lang Scala>object TextBetween extends App {
val (thisText, startDelimiter, endDelimiter) = (args(0), args(1),args(2))
 
/*
* textBetween: Get the text between two delimiters
*/
private def textBetween(thisText: String, startString: String, endString: String): String = {
var startIndex = 0
var endIndex = 0
if (startString != "start")
{
startIndex = thisText.indexOf(startString)
if (startIndex < 0) return ""
else startIndex = startIndex + startString.length
}
if (endString == "end") endIndex = thisText.length
else {
endIndex = thisText.indexOf(endString)
if (endIndex <= 0) return ""
}
 
thisText.substring(startIndex, endIndex)
} // end method textBetween
 
println(textBetween(thisText, startDelimiter, endDelimiter))
 
}</lang>
=={{header|Sidef}}==
Uses /^/ and /$/ as start and end delimiters. Additionally, the start and end delimiters can be regular expressions.
Line 2,355 ⟶ 2,383:
say "text_between(#{t{:text}.dump}, #{t{:start}.dump}, #{t{:end}.dump}) = #{r.dump}"
}</lang>
{{out}}<pre>
<pre>
text_between("Hello Rosetta Code world", "Hello ", " world") = "Rosetta Code"
text_between("Hello Rosetta Code world", /^/, " world") = "Hello Rosetta Code"
Line 2,365 ⟶ 2,392:
text_between("The quick brown fox jumps over the lazy other fox", "quick ", " fox") = "brown"
text_between("One fish two fish red fish blue fish", "fish ", " red") = "two fish"
text_between("FooBarBazFooBuxQuux", "Foo", "Foo") = "BarBaz"</pre>
</pre>
 
=={{header|UNIX Shell}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.