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.
- Go
- PHP
- C
- C++
- C#
- D
- Dart
- Dart
- Fortran
- Haskell
- JS
- Java
- Java
- Java
- Lua
- Pascal
- Perl
- Python
- Python
- Ruby
- Ruby
- Rust
- Rust
- Rust
var t = s.TrimStart(p);
var t = s.startsWith(p) ? s.substring(p.length, s.length) : s;
if (index(s,p) == 1) then
t = s(len(p)+1:)
else
t = s
end if
t = Maybe.fromMaybe s $ List.stripPrefix p s
List.stripPrefix returns Nothing if s does not start with p and returns Just strippedString if it starts with p.
Maybe.fromMaybe makes it so that we return s if the result is Nothing, or the strippedString if the result is
Just strippedString.
Maybe.fromMaybe makes it so that we return s if the result is Nothing, or the strippedString if the result is
Just strippedString.
let t = s.startsWith(p) ? s.substring(p.length) : s;
substring returns a string that starts from given index.
int i = s.indexOf(p), n = p.length();
t = i == 0 ? s.substring(n) : s;
String t = s.replaceFirst("^" + p, "");
This works if p doesn't contain any regexp control characters
local t = (s:sub(0, #p) == p) and s:sub(#p+1) or s
if (0 == index $s, $p) {
my $t = substr $s, length $p;
}
t = s.removeprefix(p)
removeprefix is in Python 3.9+
t = s.delete_prefix(p)
available since Ruby 2.5.0