如何判断一个字符串里含有,逗号 如何判断一个字符串里含有,逗号 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 String类中有方法indexOf();indexOf public int indexOf(String str)返回指定子字符串在该字符串中第一次出现处的索引。 参数: str - 子字符串。 返回: 若字符串参数作为该对象的子串出现,则返回第一个这样的子串第一个字符的索引,如果它没有作为一个子串出现则返回 -1 。 String test = "12321,asfd";String [] result = test.split( "," ) ;if( result.length > 1 ){ 有逗号} try { Pattern regex = Pattern.compile("^[^,]*$", Pattern.CANON_EQ); Matcher regexMatcher = regex.matcher(subjectString); if (regexMatcher.find()) { // regexMatcher.group(); regexMatcher.start(); regexMatcher.end(); } else { } } catch (PatternSyntaxException ex) { // Syntax error in the regular expression} if(str.indexOf(",") >= 0) System.out.println("字符串中有逗号"); true表示没有,false表示有逗号 public class GetString { public static void main(String[] args) { // TODO Auto-generated method stub String str = "12hhgdfr3,sasdf456"; int isComma = (str.indexOf(",")); if(isComma > 0) System.out.println("It has"); else System.out.println("It doesn't have"); }} 将程序改了下:public class GetString { public static void main(String[] args){ String str = "12hhgdfr3,sasdf456"; int isComma = (str.indexOf(",")); if(isComma == -1) System.out.println("It doesn't have"); else System.out.println("It has"); }} String [] result = test.split( "\\," ) ; String a = "laskdjfls,;aslkdjflkj"; if(a.indexOf(',') != 0) System.out.println("It has one ',' index of "+a.indexOf(',')); 关于数据量太大写入文本文件无法开启 quartz问题 unboxing and autoboxing 关于重写和重载 Cacheable接口是干嘛用的? 我现在正学java 不知道着重点在哪 javac命令不能用了? 怎么改变文本框的大小???? 分享:写了一个 java 调用 C语言 开发的 windows 动态库的范例 请教一下,java读取txt文件如何分块读取类似图中001-005为一块的方法 IOStream 问题,help,help!! 如 何 使 一 个 SWING 组 件 透 明。
indexOf
public int indexOf(String str)返回指定子字符串在该字符串中第一次出现处的索引。 参数:
str - 子字符串。
返回:
若字符串参数作为该对象的子串出现,则返回第一个这样的子串第一个字符的索引,如果它没有作为一个子串出现则返回 -1 。
{
有逗号
}
Pattern regex = Pattern.compile("^[^,]*$",
Pattern.CANON_EQ);
Matcher regexMatcher = regex.matcher(subjectString);
if (regexMatcher.find()) {
// regexMatcher.group(); regexMatcher.start(); regexMatcher.end();
} else {
}
} catch (PatternSyntaxException ex) {
// Syntax error in the regular expression
}
System.out.println("字符串中有逗号");
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "12hhgdfr3,sasdf456";
int isComma = (str.indexOf(","));
if(isComma > 0)
System.out.println("It has");
else
System.out.println("It doesn't have");
}
}
int isComma = (str.indexOf(","));
if(isComma == -1)
System.out.println("It doesn't have");
else
System.out.println("It has"); }}
if(a.indexOf(',') != 0)
System.out.println("It has one ',' index of "+a.indexOf(','));