首页 > 其他分享 >7.12 字符串查找

7.12 字符串查找

时间:2023-06-06 22:57:51浏览次数:38  
标签:mldn 7.12 System String println 查找 str 字符串 out

  • contains indexOf, lastIndexOf,startsWith,endWith
public class HelloWorld {
    public static void main(String args[]){// String args[]字符串数组的意思

        String str = "www.mldn.cn";
        System.out.println(str.contains("mldn"));//true
        System.out.println(str.indexOf("mldn"));//4
        System.out.println(str.indexOf("hello"));//-1
        System.out.println(str.lastIndexOf("."));//8
        System.out.println(str.lastIndexOf(".",5));//3,从第5个开始查;

        System.out.println("---------------");
        String str2 = "**@@www.mldn.cn##";
        System.out.println(str2.startsWith("**"));//true
        System.out.println(str2.startsWith("**",2));// false ,从第2个开始判断;
        System.out.println(str2.endsWith("##"));//true

    }

}

标签:mldn,7.12,System,String,println,查找,str,字符串,out
From: https://www.cnblogs.com/pansidong/p/17461976.html

相关文章

  • 7.11 字符串比较
    demo1equalsequalsIgnoreCaseStringstrA="mldn";StringstrB="MLDN";System.out.println(strA.equals(strB));System.out.println(strA.equalsIgnoreCase(strB));//不区分大小写来比较demo2compareTo字符串大小比较,com......
  • 7.10 字符串与字节
    publicclassHelloWorld{publicstaticvoidmain(Stringargs[]){//Stringargs[]字符串数组的意思Stringstr="helloworld";bytedata[]=str.getBytes();//将字符串变成字节数组for(intx=0;x<data.length;x++){data[......
  • 数据结构与算法分析(Java语言描述)(16)—— 二叉搜索树基础、节点插入、查找
    基础//二叉搜索树//由于Key需要能够进行比较,所以需要extendsComparable<Key>publicclassBinarySearchTree<KeyextendsComparable<Key>,Value>{//树中的节点为私有的类,外界不需要了解二叉搜索树节点的具体实现privateclassNode{privateKeykey;......
  • Java 深入学习(5) —— 字符串
    String对象不可变String类中每一个看起来会修改String值的方法,实际上都是创建了一个新的String对象,以包含修改后的字符串内容。publicclassTestString{staticStringupcase(Strings){returns.toUpperCase();}publicstaticvoidmain(......
  • Java代码实现带时区时间字符串转为LocalDateTime对象
    不带时区时间字符串可以使用Java8中的DateTimeFormatter类来将字符串转换为LocalDateTime对象。下面是一个示例代码:importjava.time.LocalDateTime;importjava.time.format.DateTimeFormatter;publicclassDateTimeConversionExample{publicstaticvoidmain(String[......
  • 基于《PythonCookbook》的学习(3)——利用 Shell 通配符做字符串匹配
    fnmatch模块提供了fnmatch()和fnmatchcase()两个函数可以使用通配符模式对文本进行匹配fnmatch所完成的匹配操作有点介乎于加单的字符串方法和全功能的正则表达式之间。感觉蛮鸡肋的…:(......
  • 基于《PythonCookbook》的学习(1)——针对任意多的分隔符拆分字符串
    问题:需要将字符串拆分为不同的字段,但是分隔符(以及分隔符之间的空格)在整个字符串中并不一致re.split()方法比str.split()方法更为灵活,可以为分隔符指定多个模式re.split()方法返回一个list目标字符串:In[15]:lineOut[15]:'asdasdsadas,,,,sdfdsfi///ds...ds/essd//s......
  • Java中输入字符串的方法
     Scannerinput=newscanner();Stringcode=input.next();错误写法://Stringcode=input.toString(); 1、输入字符串遇到空格或者换行结束Scannersc=newScanner(System.in);Stringstr=newString();str=sc.next();2、输入一行字符串,可以包括空格Scannersc=ne......
  • 在开发过程中,C#中@的用法,对C#程序设计来说有不错的借鉴价值。一下介绍了四种用法。 @
    在开发过程中,C#中@的用法,对C#程序设计来说有不错的借鉴价值。一下介绍了四种用法。原文链接:https://www.cnblogs.com/likui-bookHouse/p/9109872.html在开发过程中,C#中@的用法,对C#程序设计来说有不错的借鉴价值。一下介绍了四种用法。1、@是取消字符串中的转意符。比如不加@......
  • 7.9 字符串与字符
    demo1charAtpublicclassHelloWorld{publicstaticvoidmain(Stringargs[]){//Stringargs[]字符串数组的意思Stringstr="www.baidu.com";charc=str.charAt(3);//charAt可以获取某一个索引位置的字符;System.out.println(c);}......