This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
- C++
- C#
- Erlang
- Go
- Haskell
- JS
- Java
- Java
- Java
- Java
- Lisp
- Pascal
- Pascal
- Perl
- Python
- Python
- Python
- Ruby
- Ruby
- Rust
auto t = s;
t.erase(std::ranges::remove_if(t, [](const char c) { return std::isspace(c); }).begin(),t.end()) ;
String t = "";
for (char c : s.toCharArray())
if (!isWhitespace(c)) t = t + c;
String t = "";
for (char c : s.toCharArray())
switch (c) {
case ' ', '\t', '\n', '\r' -> {}
default -> t = t + c;
}
import static java.lang.Character.isWhitespace;
import static java.lang.String.valueOf;
import static java.util.stream.Collectors.joining;
String t = s.chars()
.filter(c -> !isWhitespace(c))
.mapToObj(c -> valueOf((char) c))
.collect(joining());
(defun remove-whitespace (s &aux |t|)
"Return a copy of S (a sequence) excluding all the characters space, tab, linefeed, return, and formfeed."
(setf |t|
(remove-if
(lambda (item) (find item '(#\Space #\Tab #\Linefeed #\Return #\Page)))
s))
|t|)
It would be better to simply return the result of REMOVE-IF, but the assignment requires the variable t. Note that T is a reserved constant in Lisp, so we use t (lowercase). The Lisp reader normally interns symbol names in uppercase, but enclosing the symbol name in vertical bars (pipes) forces the reader to intern the lowercase t. As the Lisp interpreter respects the case of symbol names, t is not the same name as T.
t = ''.join(s.split())
"... If sep is not specified or is None, a different splitting algorithm is applied: runs of consecutive whitespace are regarded as a single separator, and the result will contain no empty strings at the start or end if the string has leading or trailing whitespace."
programming-idioms.org