• 字符集及判断字符所在字符串位置


    //查找字符或字符串
    		int in = str2.indexOf("d");
    		
    		System.out.println("ab =" + in);
    		
    		int la = str2.lastIndexOf("d");//课后
    		
    		System.out.println("d =" + la);
    		
    		String newStr = str2.substring(5);
    		
    		newStr = str2.substring(5,6);
    		
    		System.out.println("substring() =" + newStr);
    		
    		str2 = " ab cdd s ";
    		
    		//去除前后空格
    		System.out.println("去空格 =" + str2.trim() + "后面");
    		
    		//查找替换
    		System.out.println("查找替换空格 =" + str2.replace(" ", "") + "后面");
    		
    		str2 = "abc,你好,abcd";
    		
    		System.out.println("查找替换 =" + str2.replace("abc", "李四") + "");
    		
    		System.out.println("查找替换 =" + str2.replaceFirst("abc", "张三") + "");
    		
    		str2 = "abcdef";
    		
    		//判断字符串开始和结束
    		System.out.println("判断起始1 =" + str2.startsWith("abc"));
    		
    		System.out.println("判断起始2 =" + (str2.indexOf("abc") == 0));
    		
    		System.out.println("判断结束  =" + str2.endsWith("ef") + "	");
    		
    

      

  • 相关阅读:
    JavaScript中对事件简单的理解
    正则表达式 RE模块
    模块
    面向对象进阶
    元类详细解释
    四.面向对象和函数补充
    四.函数
    Python的基础知识:
    五层协议及tcp三次握手四次挥手
    nginx常见错误
  • 原文地址:https://www.cnblogs.com/fangchongyan/p/5057173.html
Copyright © 2020-2023  润新知