This language bar is your friend. Select your favorite languages!

Idiom #147 Remove all non-ASCII characters

Create string t from string s, keeping only ASCII characters

import std.array;
import std.algorithm.iteration;
import std.ascii;
auto t = s.filter!(a => a.isASCII).array;
string t = Regex.Replace(s, @"[^\u0000-\u007F]+", string.Empty);
import "regexp"
re := regexp.MustCompile("[[:^ascii:]]")
t := re.ReplaceAllLiteralString(s, "")
import Data.Char
f = filter isAscii
t = f s
import Data.Char
t = filter isAscii s
var
  i: integer;
begin
  t := '';
  for i := 1 to length(s) do
    if s[i] < #128 then t := t + s[i];
end.
uses RegExpr;
var
  s,t: string;
begin
  t := ReplaceRegExpr('[^\u0000-\u007F]+', s, '', False);
end.
import re
t = re.sub('[^\u0000-\u007f]', '',  s)
t = s.gsub(/[[:^ascii:]]/, "")
t = s.gsub(/[^[:ascii:]]/, "")

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org