java:获取字符串中第一个不是数字或者标点符号或者空格的位置
\u4e3a\u4ec0\u4e48JAVA\u7a0b\u5e8f\u5185\u5e26\u7a7a\u683c\u7684\u5b57\u7b26\u4e32\u6bd4\u8f83\u540e\u6570\u4e0d\u51fa\u6765\uff1f\u5e94\u8be5\u662f\u88ab\u53bb\u7a7a\u683c\u4e86\uff0ctrim\uff08\uff09\uff1b
\u6bd4\u8f83\u4e2d\u53ef\u80fd\u8c03\u7528\u4e86\u8fd9\u4e2a\u65b9\u6cd5
\u4f60\u53ef\u4ee5\u628a\u7a0b\u5e8f\u8d34\u51fa\u6765\uff0c\u66f4\u597d\u89e3\u51b3
\u53ef\u4ee5\u5408\u5e76\u3002replaceAll\u65b9\u6cd5\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u6307\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\u6240\u4ee5\u4f7f\u7528\u4e00\u4e2a\u5c31\u884c\u3002
s.replaceAll("\u3002+|\uff0c+|,+|.+","\n");\u5176\u4e2d|\u4ee3\u8868\u6216\uff0c+\u4fee\u9970\u524d\u9762\u7684\u5b57\u7b26\u51fa\u73b0\u81f3\u5c111\u6b21\u3002
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String[] args) {
String testStr="122, 3. 92啊a";
String regex="[^\\p{Punct}\\p{Space}\\p{Digit}]";
Matcher matcher=Pattern.compile(regex).matcher(testStr);
if(matcher.find()) {
int index=matcher.start();
System.out.println("第一个不是数字标点或空格的位置是:"+index);
}else {
System.out.println("第一个不是数字标点或空格的位置:在该字符串中不存在!");
}
}
}
不说了,上程序,看不明白了说啊。
你这个范围有点大,不好写的(光标点符号就好多)
绛旓細String绫讳腑鏈変竴涓鏂规硶 public boolean contains锛Sting s锛夊氨鏄敤鏉ュ垽鏂綋鍓瀛楃涓鏄惁鍚湁鍙傛暟鎸囧畾鐨勫瓧绗︿覆 渚 s1=鈥渢akecatb鈥漵2=鈥渢e鈥濊鍙ワ細s1.contains(s2) //s1璋冪敤杩欎釜鏂规硶 鑻ュ叾鍊间负ture璇存槑s1鍖呭惈s2 鑻ヤ负fasle 鍒欎笉鍖呭惈
绛旓細public class Test { public static void main(String args[]) { String[] strs = {"print_printhelloworld","helloworldprint_print"};System.out.println("杈撳叆锛" + str + " ");for(String str : strs) { if(str.startsWith("print")) { System.out.println("杈撳嚭锛1");} } } }...
绛旓細} }浜屻乮ndexOf鏂规硶 1锛氭弿杩 java.lang.String.indexOf() 鐨勭敤閫旀槸鍦涓涓瓧绗︿覆涓瀵绘壘涓涓瓧鐨勪綅缃紝鍚屾椂涔熷彲浠ュ垽鏂竴涓瓧绗︿覆涓槸鍚﹀寘鍚煇涓瓧绗︺2锛氬0鏄 int indexOf(int ch,int fromIndex)3锛氳繑鍥炲 indexOf鐨勮繑鍥炲间负int 4锛氬疄渚 public static void main(String[] args) { String...
绛旓細鍦Java涓幏鍙栧瓧绗︿覆涓鎸囧畾鐨勫煎彲浠ヤ娇鐢ㄤ互涓嬪嚑绉嶆柟寮忥細鐐瑰嚮瀛︿範澶у巶鍚嶅笀绮惧搧璇1.浣跨敤substring()鏂规硶鍙互浣跨敤String绫绘彁渚涚殑substring(intbeginIndex锛宨ntendIndex)鏂规硶锛屼粠鍘熷瀛楃涓蹭腑鎴彇鍑烘寚瀹氳寖鍥寸殑瀛楃瀛愪覆銆俠eginIndex琛ㄧず鎴彇鐨勮捣濮嬩綅缃紝endIndex琛ㄧず缁撴潫浣嶇疆锛堜笉鍖呭惈锛夈2.浣跨敤StringUtils绫诲彲浠ヤ娇鐢ˋpache...
绛旓細String reg = "^(?:(?!abc).)*$";涓嶅寘鍚玜bc鐨瀛楃涓 String reg = "^(?:(?!(abc|def)).)*$";涓嶅寘鍚玜bc鎴杁ef鐨勫瓧绗︿覆
绛旓細import java.util.Scanner;public class MyClass {public static void main(String[] args) {Scanner scanf = new Scanner(System.in);System.out.println("璇疯緭鍏瀛楃涓诧細");String str = scanf.nextLine();;scanf.close();char c = str.charAt(0);System.out.print("绗竴涓瀛楃涓");if(c...
绛旓細Java涓瓧绗︿覆涓瀛愪覆鐨勬煡鎵惧叡鏈夊洓绉嶆柟娉曪紝濡備笅锛1銆乮nt indexOf(String str) 锛氳繑鍥绗竴娆″嚭鐜扮殑鎸囧畾瀛愬瓧绗︿覆鍦ㄦ瀛楃涓蹭腑鐨勭储寮曘2銆乮nt indexOf(String str, int startIndex)锛氫粠鎸囧畾鐨勭储寮曞寮濮嬶紝杩斿洖绗竴娆″嚭鐜扮殑鎸囧畾瀛愬瓧绗︿覆鍦ㄦ瀛楃涓蹭腑鐨勭储寮曘3銆乮nt lastIndexOf(String str) 锛氳繑鍥炲湪姝...
绛旓細鏄String 绫 姣斿 String str="abcdefg"str.charAt(2)2鎸囩殑 鏄浜屼釜瀛楃 鍗砪 0鎸囩殑鏄痑 鍠滄java鐨璇濆彲浠ュ姞鐧惧害缇1018283
绛旓細import java.util.Scanner;import java.util.Set;import java.util.TreeMap;/ 闇姹 锛"aababcabcdabcde",鑾峰彇瀛楃涓蹭腑姣涓涓瀛楁瘝鍑虹幇鐨勬鏁拌姹傜粨鏋:a(5)b(4)c(3)d(2)e(1)鍒嗘瀽锛欰:瀹氫箟涓涓瓧绗︿覆(鍙互鏀硅繘涓洪敭鐩樺綍鍏)B:瀹氫箟涓涓猅reeMap闆嗗悎 閿:Character 鍊硷細Integer C:鎶婂瓧绗︿覆杞崲涓哄瓧绗...
绛旓細浠ヤ笅鏄Java鑾峰彇瀛楃涓蹭腑瀛楁瘝鍑虹幇鐨勪釜鏁扮殑绀轰緥浠g爜锛歚``java import java.util.HashMap;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in);System.out.print("璇疯緭鍏涓涓瀛楃涓诧細");String input = sc.nextLine();Ha...