java字符串内容判断,str=111.23 想判断字符串中是否包括"."    字符串大小不定    

解决方案 »

  1.   


    public class testString {
    public static void main(String []args) throws ParseException{
    String a = "11.21";
    System.out.println(a.indexOf("."));
    }
    }
      

  2.   


    for(i=0;i<str.length;i  ){      if(str.charAt(i)=='.'){
                //就有'.'
          }
    }
      

  3.   

    a.indexOf("."),返回的是'.' 在字符串中的位置,一楼写的完全正确
      

  4.   

    1、用indexOf()
    2、正则表达式String s="111.23";
    String parren = "^[1-9]+\\.{1}[0-9]+$";
    Pattern p = Pattern.compile(parren);
    Matcher m = p.matcher(s);
    if(m.matches()){
        System.out.println("带点");
    }else{
        System.out.println("不带点");
    }
      

  5.   

    String str="abc.efg";
    str.indexof(".");
    这样返回的就是3即“.”在字符串中的位置,如要是没有的话就返回-1;
      

  6.   

    方法很多,正则表达式比较好,indexOf()比较简单
      

  7.   

    方法很多,正则表达式比较好,indexOf()比较简单
      

  8.   


    public class Hello { public static void main(String[] args) {
    String a = "111.23";
    int index = a.indexOf(".");
    if (index < a.length() && index > 0) {
    System.out.println("有");
    } else {
    System.out.println("没有");
    }
    }
    }
      

  9.   


        public class Test{         public static void main(String[] args) { 
                String a = "111.23"; 
                int index = a.indexOf("."); 
                if (index > a.length() || index < 0) { 
                  System.out.println("没有哦"); 
                } else { 
                   System.out.println("有的"); 
                } 
            } 

    这样就可以,也可以
    试试看吧
    多查api chm 或百度 都行啊
    希望对你有帮助
    ^_@
      

  10.   

    多种方法,较为简单的是indexOf(String str) 、lastIndexOf(String str)
    indexOf(String str) 
              返回第一次出现的指定子字符串在此字符串中的索引;
    lastIndexOf(String str) 
              返回在此字符串中最右边出现的指定子字符串的索引。
      

  11.   


    String str = "111.23";
    char [] arr = str.toCharArray();
    for(int i = 0;i < str.length();i++){
    if(arr[i] == '.'){
    System.out.println("有");
    break;
    }
    }