Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Go
import (
	"fmt"
	"strings"
	"unicode"
)
t := strings.Map(func(r rune) rune {
	if r > unicode.MaxASCII {
		return -1
	}
	return r
}, s)
import "regexp"
re := regexp.MustCompile("[[:^ascii:]]")
t := re.ReplaceAllLiteralString(s, "")
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;

New implementation...
< >
programming-idioms.org