Skip to content

Instantly share code, notes, and snippets.

@khzaw
Created December 17, 2014 11:09
Show Gist options
  • Save khzaw/6fb3b3a064a13921559f to your computer and use it in GitHub Desktop.
Save khzaw/6fb3b3a064a13921559f to your computer and use it in GitHub Desktop.
Translate unicode digits to english numerals
import java.util.regex.*;
public class RegexTest {
public static void main(String[] args) {
String burmeseNumbers = "၀၁၂၃၄၅၆၇၈၉";
String engRegex = "0|1|2|3|4|5|6|7|8|9";
String burmeseRegex = "၀|၁|၂|၃|၄|၅|၆|၇|၈|၉";
String myanmarText = "၁၉ နာရီ ၁၈ မိနစ်";
StringBuffer sb = new StringBuffer();
Pattern p = Pattern.compile(burmeseRegex, Pattern.UNICODE_CASE);
Matcher matcher = p.matcher(myanmarText);
while(matcher.find()) {
matcher.appendReplacement(sb, "" + burmeseNumbers.indexOf(matcher.group(0)));
}
matcher.appendTail(sb);
System.out.println("Original: " + myanmarText);
System.out.println("Digit Translated: " + sb.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment