Q qrenj Unregistered / Unconfirmed GUEST, unregistred user! 2003-07-09 #1 JAVA判断字符串子串问题: 比如: 求 判断'001' 是否在 字符串'001#002#'中存在的函数 或者是代码 50分
Z ZRWeng Unregistered / Unconfirmed GUEST, unregistred user! 2003-07-09 #2 public class Demo { public static void main(String[] args) { String s="001#002#'" ; String s1="001"; int index=0; index=s.indexOf(s1); if (!(index==-1)) System.out.println(s+" include "+s1); else System.out.println(s+" not include "+s1); } }
public class Demo { public static void main(String[] args) { String s="001#002#'" ; String s1="001"; int index=0; index=s.indexOf(s1); if (!(index==-1)) System.out.println(s+" include "+s1); else System.out.println(s+" not include "+s1); } }
M mazalet1 Unregistered / Unconfirmed GUEST, unregistred user! 2003-07-09 #3 你可一使用正则表达社,在jdk1。4中就有了,可以参考文挡,很容易搞定的!
J jackshow Unregistered / Unconfirmed GUEST, unregistred user! 2003-07-10 #4 用正则表达式 public class Demo { public static void main(String[] args) { String str = "001#002# "; Pattern p = Pattern.compile( "001"); Matcher m = p.matcher( str ); boolean pt = m.matches(); if (pt = true) { System.out.println("find the 001"); } } }
用正则表达式 public class Demo { public static void main(String[] args) { String str = "001#002# "; Pattern p = Pattern.compile( "001"); Matcher m = p.matcher( str ); boolean pt = m.matches(); if (pt = true) { System.out.println("find the 001"); } } }
C clever_boy_2000 Unregistered / Unconfirmed GUEST, unregistred user! 2003-07-10 #6 String.indexOf();