java中如何对一个字符串按逗号和分号分割成数组? JAVA关于将一个字符串拆分成一个字符串数组的方法
java\u4e2d\u5982\u4f55\u5bf9\u4e00\u4e2a\u5b57\u7b26\u4e32\u6309\u9017\u53f7\u548c\u5206\u53f7\u5206\u5272\u6210\u6570\u7ec4\u7528java.util.StringTokenizer\u8fd9\u4e2a\u7c7b\u6765\u5206\u9694\u6bd4\u8f83\u65b9\u4fbf\uff0c\u7528split\u4e00\u6b21\u5206\u4e0d\u5f00\u9700\u8981\u4e8c\u5c42\u5faa\u73af\u624d\u80fd\u5b8c\u6210\u3002
\u4e0b\u9762\u662f\u7528StringTokenizer\u5206\u9694\u5b57\u7b26\u4e32\u7684\u5c0f\u4f8b\u5b50\uff0c\u4f60\u770b\u770b\u3002
String str = "abc,def;gh,ij;k;lm,no,p;qr,st";
StringTokenizer st = new StringTokenizer(str,",;");
while(st.hasMoreTokens() ){
System.out.println(st.nextToken());
}
\u7528mid\u65b9\u6cd5
Mid(string, start[, length])
\u53c2\u6570
string:\u5b57\u7b26\u4e32\u8868\u8fbe\u5f0f\uff0c\u4ece\u4e2d\u8fd4\u56de\u5b57\u7b26\u3002\u5982\u679c string \u5305\u542b Null\uff0c\u5219\u8fd4\u56de Null\u3002
Start:string \u4e2d\u88ab\u63d0\u53d6\u7684\u5b57\u7b26\u90e8\u5206\u7684\u5f00\u59cb\u4f4d\u7f6e\u3002\u5982\u679c start \u8d85\u8fc7\u4e86 string \u4e2d\u5b57\u7b26\u7684\u6570\u76ee\uff0cMid \u5c06\u8fd4\u56de\u96f6\u957f\u5ea6\u5b57\u7b26\u4e32 ("")\u3002
Length:\u8981\u8fd4\u56de\u7684\u5b57\u7b26\u6570\u3002\u5982\u679c\u7701\u7565\u6216 length \u8d85\u8fc7\u6587\u672c\u7684\u5b57\u7b26\u6570\uff08\u5305\u62ec start \u5904\u7684\u5b57\u7b26\uff09\uff0c\u5c06\u8fd4\u56de\u5b57\u7b26\u4e32\u4e2d\u4ece start \u5230\u5b57\u7b26\u4e32\u7ed3\u675f\u7684\u6240\u6709\u5b57\u7b26\u3002
\u5982:Dim MyVar
MyVar = Mid("VB\u811a\u672cis fun!", 4, 6) 'MyVar \u5305\u542b "Script"\u3002
st=Mid(str,1,1)
下面是用StringTokenizer分隔字符串的小例子,你看看。
String str = "abc,def;gh,ij;k;lm,no,p;qr,st";
StringTokenizer st = new StringTokenizer(str,",;");
while(st.hasMoreTokens() ){
System.out.println(st.nextToken());
}
绛旓細String str=a,c,dfd,gggtg,dw,e;String[] str=str.split(",");
绛旓細int index=str.lastIndexOf("鏌愪釜鏍囩偣绗﹀彿");寰楀埌鐨勫氨鏄 浣犳兂瑕佺殑閭d釜鏍囩偣绗﹀彿鏈鍚庡嚭鐜扮殑浣嶇疆銆傚綋鐒 濡傛灉 杩欎釜绗﹀彿濡傛灉娌℃湁锛岃繑鍥-1 浣犲幓String绫荤殑API 涓湅锛屾湁闈炲父澶 鍏充簬瀛楃涓 澶勭悊鐨勬柟娉曠殑銆傚浼 鐪婣PI 锛屾槸闈炲父 鏈夊府鍔╃殑銆備笉鐭 绛旀 鏄惁鏄綘鎯宠鐨勩傛湰鏉ユ兂 缂栦唬鐮佺殑銆傝繕鏄 鐩存帴 ...
绛旓細public static void main(String[] args) { String str = "a涓璪鍥絚浜";char [] c = str.toCharArray();StringBuffer newStr = new StringBuffer();int incept = 0;for (int i = 0; i < c.length; i++) { String ch = ""+c[i];if(ch.getBytes().length!=incept&&i!=0){ ...
绛旓細){i++;if (i > src.length () - 1){return "";}char c = src.charAt (i);if (String.valueOf (c).matches ("[\\da-zA-Z\\!\\*\\(\\)]")){return c + convert (i, src);}else{return "%" + Integer.toString (src.charAt (i), 16).toUpperCase () + convert (...
绛旓細鎸夌収浣犵殑鎰忔濓紝鎴戞敼浜嗕笅锛屼綘鑷繁鐪嬪惂銆俻ackage org.demo.zifudemo;import java.util.*;public class TestZiFu { public static void main(String[] args) { Scanner scan = new Scanner(System.in);ZiFu zf = new ZiFu();System.out.println("璇疯緭鍏涓涓瓧绗︿覆锛");String zi = scan.next(...
绛旓細鍙互閫氳繃鈥漇canner鈥滃嚱鏁 鐩存帴杈撳叆鍙傛暟鐨勫舰寮忥紝鏉ュ疄鐜拌緭鍏ヨ鍙ワ紝涓句緥锛歩mport java.util.Scanner;public class Test { public static void main(String[] args) { Scanner input=new Scanner(System.in);System.out.println("璇疯緭鍏涓涓瓧绗鍜瀛楃涓锛");String str2=input.next()//杈撳叆涓涓瓧绗 Str...
绛旓細杩囦簡寰堜箙鎵嶇湅鍒颁綘鐨勬彁闂紝涓嶅ソ鎰忔濓紝甯屾湜瀵逛綘鏈夊府鍔╋細import java.util.Scanner;public class IoTest { public static void main(String[] args) { Scanner input = new Scanner(System.in);String str1 = input.nextLine();//杈撳叆涓涓瓧绗︿覆 String str2 = input.nextLine();//鎸囧畾瀛楃 String...
绛旓細閭e鏋滄渶鍚涓涓鏄暟瀛楄鎬庝箞鍔烇紵import java.util.Scanner;public class _20140919 {/** * @param args */public static void main(String[] args) {//杈撳叆瀛楃涓睸tring str=new Scanner(System.in).nextLine().toString();//灏嗗瓧绗︿覆杞垚瀛楃鏁扮粍char[] charArr=str.toCharArray();//瀹氫箟涓涓...
绛旓細import java.util.Scanner;public class Dame1 { public static void main(String[] args) { Scanner san = new Scanner(System.in) ;System.out.println("杈撳叆涓涓瓧绗︿覆");String getString = san.nextLine();//浠庨敭鐩樿緭鍏ュ瓧绗︿覆 System.out.println("杈撳叆瑕佹煡鎵剧殑瀛楃");String index = san...
绛旓細鎬濊矾鏄繖鏍风殑锛屽洜涓瀛楃涓茬殑璇濆畠涔熺畻鏄暟缁勶紝鎵浠ヨ浣犲彲浠ヤ粠澶村紑濮嬮亶鍘嗚繖涓暟缁勭殑姣忎竴涓厓绱狅紙涔熷氨鏄瀛楃涓查噷鐨姣忎釜瀛楃锛夛紝鐒跺悗姣忔閮藉幓鍜屾煇涓涓瓧绗﹁繘琛屾瘮杈冿紝濡傛灉涓鏍风殑璇濓紝灏辩疮鍔犲畠鍑虹幇鐨勪竴涓鏁帮紝鍚﹀垯灏辫繘琛屼笅涓涓瓧绗︾殑姣旇緝锛岀洿鍒板惊鐜粨鏉熴備唬鐮佸涓嬶細public class Test { public static void ...