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 ptnSpace = Pattern.compile("\\s");
8 private static Pattern ptnAscii = Pattern.compile("\\p{ASCII}");
10 public static String parseSubstring(String text, int length){
11 int len = text.length();
15 for (int i = 0; i < len + 1 && i < length + 1; i++){
20 String ch = text.substring(i, i + 1);
22 if (ptnAlnum.matcher(ch).matches()){
30 else if (ptnSpace.matcher(ch).matches()){
36 else if (ptnAscii.matcher(ch).matches()){
50 return text.substring(0, (len < length)? len : length);
52 return text.substring(0, pos);