Last active
August 5, 2021 17:11
-
-
Save ArefMozafari/837925cb3771ea7f9c14cb783ab54b3f to your computer and use it in GitHub Desktop.
Flutter/Dart - How to convert En/Fa entered number to each other
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension StringExtentions on String { | |
String replaceFaNumToEnNum() { | |
const english = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; | |
const farsi = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']; | |
String value = this; | |
for (int i = 0; i < farsi.length; i++) { | |
value = value.replaceAll(farsi[i], english[i]); | |
} | |
return value; | |
} | |
String replaceEnNumToFaNum() { | |
if (this == null || this.isEmpty) return this; | |
const english = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; | |
const farsi = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']; | |
String value = this; | |
for (int i = 0; i < english.length; i++) { | |
value = value.replaceAll(english[i], farsi[i]); | |
} | |
return value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment