zoukankan      html  css  js  c++  java
  • StringDemo

    package cn.zuoye;
    /*
     * string类的其他功能
     *
     * 替换功能
     * string replace (char old ,char new)
     * string replace (string old,string new)
     *
     * 去除字符串两个空格(两边)
     * string trim()
     *
     * 按字典顺序比较两个字符串
     * int compareTo(String str)
     * int compareToIgnoreCase(String str)
     */
    public class StringDemo {
     public static void main(String[] args) {
      // 替换功能
      String s1 = "helloworld";
      String s2 = s1.replace('l', 'k');
      System.out.println("s1:"+s1);//s1:helloworld
      System.out.println("s2:"+s2);//s2:hekkoworkd
      
      //去除字符串两空格
      String s3 = "  hello world   ";
      String s4 = s3.trim();
      System.out.println("s3:"+s3+"++++");//s3:  hello world   ++++
      System.out.println("s4:"+s4+"++++");//s4:hello world++++
      
      //按字典顺序比较两个字符串
      String s5 = "hello";
      String s6 = "hello";
      String s7 = "abc";
      String s8 = "xyz";
      System.out.println(s5.compareTo(s6));//0
      System.out.println(s5.compareTo(s7));//7
      System.out.println(s5.compareTo(s8));//-16
        
     }
    }
  • 相关阅读:
    SQL 函数以及SQL 编程
    查询练习(四十五道题)
    SQL server 高级查询
    SQL server 数据库 操作及简单查询
    T-SQL 语句
    SQL
    表单验证、实则表达式、事件
    视频插入代码
    插入地图
    网页布局小练
  • 原文地址:https://www.cnblogs.com/rong123/p/9894434.html
Copyright © 2011-2022 走看看