Skip to content

Instantly share code, notes, and snippets.

@yamatatsu10969
Created February 10, 2022 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yamatatsu10969/424abf3e030eb5218880aa2893d78f72 to your computer and use it in GitHub Desktop.
Save yamatatsu10969/424abf3e030eb5218880aa2893d78f72 to your computer and use it in GitHub Desktop.
Full width number to half width number
const _fullLengthCode = 65248;
extension StringExtension on String {
String toHalfWidthNumber() {
final regex = RegExp(r'^[0-9]+$');
final string = runes.map<String>((rune) {
final char = String.fromCharCode(rune);
return regex.hasMatch(char)
? String.fromCharCode(rune - _fullLengthCode)
: char;
});
return string.join();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment