1 package com.yuji.tdb.utility;
3 import java.util.regex.Pattern;
5 public class StringUtility {
6 private static Pattern ptnAlnum = Pattern.compile("[a-zA-Z0-9]");
7 private static Pattern ptnAscii = Pattern.compile("\\p{ASCII}");
9 public static String parseSubstring(String text, int length){
10 int len = text.length();
14 for (int i = 0; i < len + 1 && i < length + 1; i++){
19 String ch = text.substring(i, i + 1);
21 if (ptnAlnum.matcher(ch).matches()){
27 else if (ptnAscii.matcher(ch).matches()){
39 return text.substring(0, (len < length)? len : length);
41 return text.substring(0, pos);