package untitled6;
/**
* 关于字符串的几个处理方法
*/
import java.util.*;
public class Untitled1 {
String str;
public Untitled1() {
}
public static void main(String[] args) {
String test = "92###12312321#长风#431226197909230619##11#BEJ";
String test0 = " 1 2 5 6 7 ";
Untitled1 ut = new Untitled1();
ut.getFields(test);
}
public static String[] getFields(String test) { //坼分字符
String sep = "/u0020";
if (test.indexOf(sep) != -1) {
if ( (test.indexOf(sep) > test.indexOf("#")) &&
test.indexOf("#") != -1) {
sep = "#";
}
}
else {
sep = "#";
}
String[] st;
List flds = new ArrayList();
if (sep.equals("/u0020")) {
StringTokenizer stto = new StringTokenizer(test.trim(), sep);
while (stto.hasMoreTokens()) {
flds.add(stto.nextToken());
}
st = (String[]) flds.toArray(new String[stto.countTokens()]);
}
else {
st = test.trim().split(sep);
}
System.out.println(st.length);
return st;
}
public void hashtableTest() { //判断ht里面的键值的元素的长度!
Hashtable ht = new Hashtable();
ht.put("11", "qqqqqqqqqq");
ht.put("12", "sssssssssssss");
int i = 0;
Enumeration keys = ht.keys();
for (; keys.hasMoreElements(); ) {
String obj = (String) keys.nextElement();
int test = 2;
if (obj.trim().length() == test) {
}
else {
}
}
}
public void chefen(String str, String s) { //str:获取字符串在字符中的位置,s:间隔字符。
int a_length = 1;
int pre = str.indexOf(s);
for (int i = 0; i < str.length(); i++) { //a_length:获取字符串里$的数量
pre = str.indexOf(s, pre + 1);
if (pre >= 0) {
a_length++;
}
else {
break;
}
}
int a[] = new int[a_length];
System.out.println(a.length);
String st[];
if (a_length % 2 == 0) {
st = new String[a_length / 2];
}
else {
st = new String[ (a_length - 1) / 2];
}
System.out.println(st.length);
for (int i = 1; i < a.length; i++) { //获取$出现的位置的一堆数组
a[0] = str.indexOf(s);
a[i] = str.indexOf(s, a[i - 1] + 1);
}
for (int i = 0, m = 0; m <= st.length && i < a.length; i++, m++) { //获取$i$的字符串数组
st[m] = str.substring(a[i], a[i + 1] + 1);
i++;
System.out.println(m + ":" + st[m]);
}
}
}