java字符串截取split();

package test1;

/*
 * Split的两种用法+类似的其他方法
 */
public class TestSplit {
	public static void main(String[] args) {
		String s = "abc=123";
		String[] a = s.split("=");
		System.out.println(a[0]);
		System.out.println(a[1]+"\n");

		String s2 = "a=123$b=456";
		String[] j = s2.split("$");
		String[] str2;
		for (int i = 0; i < j.length; i++) {
			String str = j[i];
			str2 = str.split("=");
			System.out.println(str2[0]);
			System.out.println(str2[1]);
			System.out.println(str2[2]+"\n");
		}
		String str = "abc=123";
		int equalIndex = str.indexOf("=");
		if (equalIndex > -1) {
			String value = str.substring(equalIndex + 1);
			System.out.println(value);
		}
	}

}

posted @ 2022-01-27 18:36  zhangdaopin  阅读(82)  评论(0编辑  收藏  举报