如何判断一个字符串里含有,逗号

javashhai6 2005-12-01 04:00:15
如何判断一个字符串里含有,逗号
...全文
2633 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
crazycy 2005-12-03
  • 打赏
  • 举报
回复
String [] result = test.split( "\\," ) ;
dj0517 2005-12-03
  • 打赏
  • 举报
回复
将程序改了下:

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");

}

}
believefym 2005-12-03
  • 打赏
  • 举报
回复
楼上的错
greenteanet 2005-12-03
  • 打赏
  • 举报
回复
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");
}
}
leekooqi 2005-12-03
  • 打赏
  • 举报
回复
String a = "laskdjfls,;aslkdjflkj";
if(a.indexOf(',') != 0)
System.out.println("It has one ',' index of "+a.indexOf(','));
fog628 2005-12-01
  • 打赏
  • 举报
回复
true表示没有,false表示有逗号
fog628 2005-12-01
  • 打赏
  • 举报
回复
s.matches("^[^,]*$")
PigBrother 2005-12-01
  • 打赏
  • 举报
回复
if(str.indexOf(",") >= 0)
System.out.println("字符串中有逗号");
iwhp 2005-12-01
  • 打赏
  • 举报
回复
检索字符串,发现逗号的话,输出就ok了
rcom10002 2005-12-01
  • 打赏
  • 举报
回复
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
}
vvpang 2005-12-01
  • 打赏
  • 举报
回复
啊。。。我的方法是错的。。。

我楼上的楼上的,正确的。
yyouyou 2005-12-01
  • 打赏
  • 举报
回复
String类中有方法indexOf();
indexOf
public int indexOf(String str)

返回指定子字符串在该字符串中第一次出现处的索引。

参数:
str - 子字符串。
返回:
若字符串参数作为该对象的子串出现,则返回第一个这样的子串第一个字符的索引,如果它没有作为一个子串出现则返回 -1 。
vvpang 2005-12-01
  • 打赏
  • 举报
回复
String test = "12321,asfd";

String [] result = test.split( "," ) ;

if( result.length > 1 )
{
有逗号
}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧