在JAVA里有没有什么方法把字符串分割为单个字符?!就是拆分~ 用java语言把字符串分割成单个字符,如“我ABC”
java\u4e2d\u600e\u6837\u521b\u5efa\u4e00\u4e2a\u65b9\u6cd5\uff0c\u628a\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\u5206\u89e3\u6210\u5355\u4e2a\u5b57\u7b26\uff0c\u8be6\u60c5\u8865\u5145\u5982\u4e0b\uff1apublic void GetFirstChar(string a)
{
char[] s= a.ToCharArray(); //\u5c06\u5236\u5b9a\u7684\u5b57\u7b26\u4e32 \u5206\u89e3\u540e\uff0c\u63d2\u5165\u5230Char\u6570\u7ec4\u3002
for (int i = 0; i < s.Length; i++)
{
Response.Write("alert('"+s[i]+"')"); //\u5faa\u73af\u663e\u793a
}
}
\u5916\u884c\u770b\u70ed\u95f9 \u5185\u884c\u770b\u95e8\u9053
String str = "gbehgbhwege";
String[] split = str.split("|");
for (String s : split) {
System.out.println(s);
}
\u5c31\u53ef\u4ee5\u4e86 | \u6216\u8005 \u7528 "" \u5206\u5272\u4e5f\u80fd\u8fbe\u5230\u5355\u4e2a\u5206\u5272\u7684\u76ee\u7684
String 有个split(char)方法将按char的类型把他分割成数组如:a-b-c-d-e-f 则用String.split("-")
String有个toCharArray()方法将字符串分成单个字符的数组
StringTokenizer itr=new StringTokenizer(string)
可以把string字符串分成一个一个单词
"abcde fgh".trim().split("");
toCharArray()
绛旓細妤间富浣犲ソ锛屽緢楂樺叴鑳藉洖绛斾綘杩欎釜寰堟湁鎸戞垬鎬х殑闂锛岄鍏堟垜璋堣皥鎴戝涓婇潰9涓緥瀛愮殑鐞嗚В锛屽嵆杩欎釜鏂规硶搴旇瀹炵幇鐨勫姛鑳斤細杩欎釜鏂规硶涓嶫DK String鍘熸湁鐨勬柟娉substring鏄湁鍖哄埆鐨勶紝鍦ㄨ繖涓鏂规硶閲锛屼竴涓腑鏂囨眽瀛楃浉褰撲簬鍗2涓嫳鏂囧瓧绗︾殑浣嶇疆銆傝屼笖鏍规嵁鏂规硶浼犲叆鐨勫弬鏁皃Start鍜宲End鍦ㄨ繑鍥炵浉搴旂殑瀛愬瓧绗︿覆child 濡傛灉pstart鍒氬ソ鍦...
绛旓細toStrng 娌℃湁arguments override:public String toString(){ // insert you code return "informations" } 鍥犱负鍦╦ava涓 Object绫绘槸鍩虹被,鎵浠ユ瘡涓被閮戒細鏈塼oString鏂规硶銆 System.out.println(Object)瀹為檯涓婂氨鏄皟鐢 object鐨則oString鏂规硶銆 鎴戜滑鐢ㄧ殑姣旇緝澶氱殑灏辨槸 String绫荤殑toString 鏂规硶,String绫婚噸鍐欎簡Object鐨則oStri...
绛旓細鍏抽敭瀛梥uper銆鍦↗ava绋嬪簭涓紝鎶婂叧閿瓧(super)鍔犲埌鏂规硶鍚嶇О鐨勫墠闈紝鍙疄鐜板瓙绫昏皟鐢ㄧ埗绫鐨勬柟娉銆
绛旓細鍙涓や釜鍑芥暟娌℃湁浠涔鍖哄埆锛屼笅闈㈠皢瀛楃涓蹭腑鐨勨淺\鈥濇浛鎹负鈥++鈥漇ystem.out.println(x.replace("\\", "++")); 娌℃湁闂 System.out.println(x.replaceAll("\\", "++")); 鎶ラ敊 java.util.regex.PatternSyntaxException 鍙锛屽綋浣跨敤杞箟瀛楃杩涜鏇挎崲鐨勬椂鍊欙紝鏄湁鍖哄埆鐨勩俽eplaceAll鐨勫弬鏁板氨...
绛旓細StringBuilder鍜孲tringBuffer鏈変粈涔鍖哄埆锛烻tringBuilder鍜孲tringBuffer鐨勫姛鑳芥病鏈夋樉钁楀尯鍒紝闄や簡娑堥櫎闈炵嚎绋嬪畨鍏ㄩ棶棰橈紝鏈夋晥鍦伴檷浣庝簡鎴愭湰浠ュ锛屽湪澶у鏁版儏鍐典笅鏄閫夌殑瀛楃涓茶繛鎺ラ夐」銆係tringBuffer鎻愪緵浜嗕竴涓被鏉ヨВ鍐冲钩閾洪《閮ㄨ繃澶氱殑涓棿瀵硅薄鐨勯棶棰橈紝鎴戜滑鍙互浣跨敤Append鎴朅dd鏂规硶灏瀛楃涓叉坊鍔犲埌鐜版湁搴忓垪鐨勬湯灏炬垨鎸囧畾浣嶇疆...
绛旓細鏂规硶涓锛歱ublic static void main(String[] args) throws Exception{ Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2005-06-09");String now = new SimpleDateFormat("yyyy骞碝M鏈坉d鏃").format(date);System.out.println(now);} 杈撳嚭缁撴灉锛2005骞06鏈09鏃 鏂规硶浜岋細public class ...
绛旓細鏁扮粍涓彁鍙栫浉鍚岀殑瀛楁瘝锛屽彲浠ヤ娇鐢╯tring鐨刢harat鏂规硶閬嶅巻瀛楁瘝锛屾斁鍒颁竴涓猻tring涓紝鎵惧埌涔嬪悗鍒犻櫎鎺夎繖涓瓧姣嶏紝鎺ョ潃閬嶅巻涓嬩竴涓紝绀轰緥濡備笅锛歱ackage test1;import java.util.Random;public class ArrayTest {public static void main(String[] args) {//1銆佹瀯寤轰竴涓暟缁凷tring[] array={"a","b","c","d"...
绛旓細杩欎釜鏂规硶涓嶆槸jdk鑷甫鐨勶紝闇瑕佽嚜宸卞啓锛屽弬鑰冨涓嬶細public String reverseSting(String inputString) { char[] inputStringArray = inputString.toCharArray();String reverseString = "";for (int i = inputStringArray.length - 1; i >= 0; i--) { reverseString += inputStringArray[i];} retur...
绛旓細java鐨JtextPane娌℃湁append鏂规硶锛屽彲浠ヤ娇鐢―ocument鏉ユ坊鍔犳枃鏈紝渚嬪瓙濡備笅锛//璁剧疆瀛椾綋澶у皬 SimpleAttributeSet attrset = new SimpleAttributeSet(); StyleConstants.setFontSize(attrset,24); //鎻掑叆鍐呭 JTextPane textPane = new JTextPane(); Document docs = textPane.getDocument();//鑾峰緱...
绛旓細鐜板湪鎴戜滑瑕佽鎺у埗axman绉诲姩鍒伴《閮ㄤ负10鐨勪綅缃:eval(str);杩欐牱杩欎釜瀛楃涓插氨鍙樻垚浜嗚〃杈惧紡鎴栬鍙ュ紑濮嬫墽琛.杩欐牱鐨勫姛鑳藉浜庡姩鎬佹瀯閫犲彉閲忔槸鏈夐潪甯搁噸瑕佺殑 鎰忎箟.閭d箞鍦╦ava涓,濡傛灉瀹炵幇杩欎釜鍔熻兘鍛?鍏跺疄鎴戜滑鍙互鐢ㄥ姩鎬佺紪璇戞潵瀹炵幇銆傚亣璁炬湁涓缁鏂规硶瀹炵幇涓嶅悓鐨勫姛鑳,鐜板湪瑕佹牴鎹紶杩涙潵鐨勬柟娉曞悕璋冪敤鐩稿簲鐨勬柟娉,鍋囧娌℃湁eval...