자바
돈에 ,찍기나 전화번호에 -찍는 등의 정규식.
newkie
2011. 4. 21. 18:07
public String addComma(long num)
{
DecimalFormat decimalFormat = new DecimalFormat("#,###");
return decimalFormat.format(num);
}
1234567890을 넣으면 1,234,567,890이 되어 나옴
public static String addDash(String noStr)
{
Pattern tellPattern = Pattern.compile( "^(01\\d{1}|02|0\\d{1,2})-?(\\d{3,4})-?(\\d{4})");
if(noStr == null)
{
return noStr;
}
noStr = noStr.trim();
Matcher matcher = tellPattern.matcher( noStr);
if(matcher.matches())
{
return matcher.group( 1) + "-" + matcher.group( 2) + "-" + matcher.group( 3);
}
else
{
return noStr;
}
}
01012345678 을 넣으면 010-2345-6789가 되어 나옴
토나오는 정규식