Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
- Clojure
- Clojure
- Cobol
- C++
- C#
- D
- Dart
- Elixir
- Elixir
- Erlang
- Fortran
- Go
- Go
- Groovy
- Haskell
- JS
- Java
- Java
- Kotlin
- Lisp
- Obj-C
- PHP
- Pascal
- Perl
- Python
- Ruby
- Ruby
- Rust
- Rust
- Smalltalk
- VB
- VB
(def t
(when (string? s)
(let [from (-> s (count) (- 5) (max 0))]
(subs s from))))
when with string? take care of nil and other types.
max takes care of strings shorter than 5.
-> (arguably) for readability.
subs uses java.lang.String/substring
max takes care of strings shorter than 5.
-> (arguably) for readability.
subs uses java.lang.String/substring
IDENTIFICATION DIVISION.
PROGRAM-ID. suffix.
PROCEDURE DIVISION.
MOVE FUNCTION LENGTH(s) TO len
COMPUTE pos = (len - 5) + 1
MOVE s(pos:) TO t
STOP RUN.
string t = s[$-5..$];
<<_ :: binary-5>> <> t = s
character(len=5) :: t
t = s(len(s)-4:)
t := s
r := []rune(s)
if len(r) > 5 {
t = string(r[len(r)-5:])
}
Convert to []rune because some characters are two or more bytes long.
t = drop (length s - 5) s
int i = s.length() - 5;
if (isSurrogate(s.charAt(i))) --i;
String t = s.substring(i);
(setf *t* (subseq s (- (length s) 5)))
$t = mb_substr($s, -5, null, 'UTF-8');
Function RightStr(const AText: AnsiString; const ACount: Integer): AnsiString;
var j,l:integer;
begin
l:=length(atext);
j:=ACount;
if j>l then j:=l;
Result:=Copy(AText,l-j+1,j);
end;
Function RightStr() is part of the StrUtils unit that comes with FreePascal.
t = s[-5:]
t = s[-5..]
endless ranges were added in Ruby 2.6
let last5ch = s.chars().count() - 5;
let t: String = s.chars().skip(last5ch).collect();
let s = "a̐éö̲\r\n";
let t = s.grapheme_indices(true).rev().nth(5).map_or(s, |(i,_)|&s[i..]);
s last: 5
t = Right(s, 5)
t = s.Substring(s.Length - 5)