1 23 24 package org.dbforms.util; 25 26 27 import java.util.StringTokenizer ; 28 import java.util.Vector ; 29 30 31 32 33 39 public class StringUtil { 40 41 60 public static String getEmbeddedString(String str, 61 int afterDelims, 62 char delim) { 63 int lastIndex = 0; 64 65 for (int i = 0; i < afterDelims; i++) { 66 lastIndex = str.indexOf(delim, lastIndex) + 1; } 68 69 int nextIndex = str.indexOf(delim, lastIndex); 71 if (nextIndex == -1) { 72 int dotIndex = str.lastIndexOf('.'); 74 nextIndex = (dotIndex == -1) ? str.length() 75 : dotIndex; 76 } 77 78 return str.substring(lastIndex, nextIndex); 79 } 80 81 91 public static int getEmbeddedStringAsInteger(String str, 92 int afterDelims, 93 char delim) { 94 return Integer.parseInt(getEmbeddedString(str, afterDelims, delim)); 95 } 96 97 121 public static String getEmbeddedStringWithoutDots(String str, 122 int afterDelims, 123 char delim) { 124 int lastIndex = 0; 125 126 for (int i = 0; i < afterDelims; i++) { 127 lastIndex = str.indexOf(delim, lastIndex) + 1; } 129 130 int nextIndex = str.indexOf(delim, lastIndex); 132 if (nextIndex == -1) { 133 nextIndex = str.length(); 134 } 135 136 return str.substring(lastIndex, nextIndex); 137 } 138 139 149 public static Vector splitString(String str, 150 String delimeter) { 151 Vector result = new Vector (); 152 StringTokenizer st = new StringTokenizer (str, delimeter); 153 154 while (st.hasMoreTokens()) 155 result.addElement(st.nextToken()); 156 157 return result; 158 } 159 160 } 161 | Popular Tags |