This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
- Clojure
- C#
- Dart
- Go
- Haskell
- JS
- JS
- Java
- Java
- Java
- Java
- Java
- Lisp
- Pascal
- Pascal
- Perl
- Perl
- Python
- Python
- Ruby
- Rust
String t = s.chars()
.filter(Character::isDigit)
.mapToObj(x -> valueOf((char) x))
.collect(joining());
String t = "";
char c;
int i, n = s.length();
for (i = 0; i < n; ++i)
if (isDigit(c = s.charAt(i)))
t = t + c;
String t = "";
for (char c : s.toCharArray())
if (isDigit(c)) t = t + c;
($t = $s) =~ tr/0-9//cd;
tr/// translates characters, in this case the complement of 0 through 9 as dictated by the c modifier. The d modifier deletes found but unmatched characters, which will be everything except digits. More efficient than using a regex.