Issue
I'm new in Dart
and flutter
.
I want to replace English number with Farsi number. How can implement this?
1-2-3-4-5-6-7-8-9 ==> ۱-۲-۳-۴-۵-۶-۷-۸-۹
Solution
Example:
String replaceFarsiNumber(String input) {
const english = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
const farsi = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
for (int i = 0; i < english.length; i++) {
input = input.replaceAll(english[i], farsi[i]);
}
return input;
}
main() {
print(replaceFarsiNumber('0-1-2-3-4-5-6-7-8-9')); // ==> ۰-۱-۲-۳-۴-۵-۶-۷-۸-۹
}
Answered By - Xavier
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.