java API 常用字串方法

2021-07-11 06:14:34 字數 840 閱讀 9847

string s="  abc  abc  abc     ";

system.out.println("1位置字元:"+s.charat(1));

system.out.println("2位置字元:"+s.charat(2));

system.out.println("變大寫:"+s.tolowercase());

system.out.println("長度:"+s.length());

system.out.println("比大小:"+s.compareto("  xyz"));

system.out.println("字首:"+s.startswith(" abc"));

system.out.println("字尾:"+s.endswith("abc"));

system.out.println("找bc起始位置:"+s.indexof("bc"));

system.out.println("從4向後找bc:"+s.indexof("bc",4));

system.out.println("最後乙個bc:"+s.lastindexof("bc"));

system.out.println("找不存在的字串:"+s.indexof("***x"));

system.out.println("a替換成*:"+s.replace('a', '*'));

system.out.println("擷取6到末尾:"+s.substring(6));

system.out.println("擷取【6,10):"+s.substring(6, 10));

system.out.println("去除兩端空格:"+s.trim());

常用字串方法

1 返回指定位置的字元 charat 方法可返回指定位置的字元。str.charat 指定位置 2 替換字串中的乙個或者幾個字元 replace 被替換的字元,新替換的字元 若第二個引數為空也可用於刪除特定字元,執行乙個全域性替換 var str mr blue has a blue house a...

mysql常用字串 MYSQL常用字串函式寶典

mysql常用字串函式 想更進一步加強自己在查詢語句方面的能力,需要掌握常用函式。字串函式 1 concat s1,s2,sn 將s1,s2,sn串聯成乙個字串。exp root test 14 43 desc t1 field type null key default extra id int ...

js常用字串方法

eg var string can you help me?方法 例子 描述結果 string.substring 2,5 擷取指定字串索引為2至5 不包括5 間的的字串 n y string.substr 2,5 從指定字串索引為2的地方擷取數量為5的字串 n you string.indexof...