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.
- Python
- Python
- Python
- Python
- Python
- Ada
- Clojure
- C++
- C#
- D
- Dart
- Elixir
- Elixir
- Fortran
- Go
- Go
- Haskell
- Haskell
- JS
- JS
- Java
- Java
- Java
- Lisp
- PHP
- Pascal
- Pascal
- Perl
- Perl
- Ruby
- Ruby
- Rust
- Rust
- Smalltalk
f = lambda x: ord(x) < 0x80
t = ''.join(filter(f, s))
t = s.encode("ascii", "ignore").decode()
function Only_ASCII (S : String) return String is
subtype ASCII is Character range
Character'Val (0) .. Character'Val (127);
T : String (S'Range);
Last : Natural := T'First - 1;
begin
for Char of S loop
if Char in ASCII then
Last := Last + 1;
T (Last) := Char;
end if;
end loop;
return T (T'First .. Last);
end Only_ASCII;
copy_if(begin(src), end(src), back_inserter(dest),
[](const auto c) { return static_cast<unsigned char>(c) <= 0x7F; });
var t = '';
for(var c in s.runes) {
if(c < 128){
t = t + String.fromCharCode(c);
}
}
t =
s
|> String.to_charlist()
|> Enum.filter(&(&1 in 0..127))
|> List.to_string
t = for <<c <- s>>, c in 0..127, into: "", do: <<c>>
n = 0
do i=1,len(s)
if (iachar(s(i:i)) <= 127) n = n + 1
end do
allocate (character(len=n) :: t)
j = 0
do i=1,len(s)
if (iachar(s(i:i)) <= 127) then
j = j + 1
t(j:j) = s(i:i)
end if
end do
t := strings.Map(func(r rune) rune {
if r > unicode.MaxASCII {
return -1
}
return r
}, s)
const t = [...s].filter(c => c.charCodeAt(0) <= 0x7f).join('')
const t = s.replace(/[^\x00-\x7f]/gu, '')
String t = s.replaceAll("[^\\p{ASCII}]+", "");
String t = s.replaceAll("[^\\x00-\\x7F]", "");
(remove-if-not (lambda (i) (<= 0 i 127))
s
:key #'char-code)
$t = preg_replace('/[^[:ascii:]]/', '', $s);
var
i: integer;
begin
t := '';
for i := 1 to length(s) do
if s[i] < #128 then t := t + s[i];
end.
This is the lazy and slow way.
Plenty of room for optimization ;-)
Plenty of room for optimization ;-)
($t = $s) =~ s/[^\x00-\x7f]+//g;
Assign s to t and then operate on t, by removing the complement of the set of ASCII characters.
t = s.gsub(/[[:^ascii:]]/, "")
t = s.gsub(/[^[:ascii:]]/, "")
t := s select: [:character | character isAscii].