Created
December 17, 2014 11:09
-
-
Save khzaw/6fb3b3a064a13921559f to your computer and use it in GitHub Desktop.
Translate unicode digits to english numerals
This file contains 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
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