Substring/Top and tail: Difference between revisions

Add Ecstasy example
m (→‎{{header|Wren}}: Minor tidy)
(Add Ecstasy example)
 
(2 intermediate revisions by one other user not shown)
Line 734:
 
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
strings$ = "EasyLangEasylang"
print substr strings$ 1 (len strings$ - 1 # Without the last character)
print substr strings$ 2 (len strings$ - 1 # Without the first character)
print substr strings$ 2 (len strings$ - 2 # Without the first and last characters)
</syntaxhighlight>
{{out}}
<pre>
Easylan
EasyLan
asylang
asyLang
asylan
asyLan
</pre>
 
=={{header|Ecstasy}}==
Generally, extracting substrings in Ecstasy is most easily performed using the slice operator, but there is also a <code>substring()</code> method:
 
<syntaxhighlight lang="ecstasy">
module Substrings {
void run(String[] args = []) {
String s = args.size > 0 ? args[0] : "hello";
@Inject Console console;
console.print(
$|Original : { s .quoted()=}
|Remove first: { s.substring(1) .quoted()=}
|Remove first: {(s.size < 1 ? "" : s[1..<s.size ]).quoted()=}
|Remove last : {(s.size < 1 ? "" : s[0..<s.size-1]).quoted()=}
|Remove both : {(s.size < 2 ? "" : s[1..<s.size-1]).quoted()=}
);
}
}
</syntaxhighlight>
 
{{out}}
<pre>
x$ xec Substrings
Original : s .quoted()="hello"
Remove first: s.substring(1) .quoted()="ello"
Remove first: (s.size < 1 ? "" : s[1..<s.size ]).quoted()="ello"
Remove last : (s.size < 1 ? "" : s[0..<s.size-1]).quoted()="hell"
Remove both : (s.size < 2 ? "" : s[1..<s.size-1]).quoted()="ell"
x$ xec Substrings a
Original : s .quoted()="a"
Remove first: s.substring(1) .quoted()=""
Remove first: (s.size < 1 ? "" : s[1..<s.size ]).quoted()=""
Remove last : (s.size < 1 ? "" : s[0..<s.size-1]).quoted()=""
Remove both : (s.size < 2 ? "" : s[1..<s.size-1]).quoted()=""
x$ xec Substrings ab
Original : s .quoted()="ab"
Remove first: s.substring(1) .quoted()="b"
Remove first: (s.size < 1 ? "" : s[1..<s.size ]).quoted()="b"
Remove last : (s.size < 1 ? "" : s[0..<s.size-1]).quoted()="a"
Remove both : (s.size < 2 ? "" : s[1..<s.size-1]).quoted()=""
x$ xec Substrings abc
Original : s .quoted()="abc"
Remove first: s.substring(1) .quoted()="bc"
Remove first: (s.size < 1 ? "" : s[1..<s.size ]).quoted()="bc"
Remove last : (s.size < 1 ? "" : s[0..<s.size-1]).quoted()="ab"
Remove both : (s.size < 2 ? "" : s[1..<s.size-1]).quoted()="b"
</pre>
 
162

edits