zoukankan      html  css  js  c++  java
  • Java——字符串操作

     1 /**
     2  *  java字符串操作
     3  * @author wydream
     4  *
     5  */
     6 
     7 public class StringTest {
     8 
     9     public static void main(String[] args) {
    10         String str="abCdeFg";
    11         
    12         //1.length():统计字符串长度
    13         System.out.println(str.length());
    14         
    15         //2.indexOf:查找指定字符再字符串中的位置
    16         System.out.println(str.indexOf("b"));
    17         
    18         //3.toUpperCase:小写转大写
    19         System.out.println(str.toUpperCase());
    20         
    21         //4.toLowerCase:大写转小写
    22         System.out.println(str.toLowerCase());
    23         
    24         //5.substring:截取字符串
    25         System.out.println(str.substring(0,3));
    26         System.out.println(str.substring(3));
    27         
    28         //6.replaceAll:替换当前字符串中指定的内容
    29         str.replaceAll("ab", "xy");
    30         System.out.println(str);
    31         
    32         //7.trim:去掉当前字符串中两端的空格
    33         str="  adeg efe efe ";
    34         System.out.println(str.trim());
    35         
    36         //8.+:字符串拼接
    37         String str1="I LOVE ";
    38         String str2="YOU";
    39         System.out.println(str1+str2);
    40         
    41         //9 将字符串变为整数
    42         String str3="123";
    43         int num=Integer.parseInt(str3);
    44         System.out.println(num);
    45         
    46         
    47     }
    48     
    49 }
  • 相关阅读:
    C++中struct和class的区别
    关于LBP特征等价模式的解释
    常用的颜色模型
    flask类装饰器
    flask的方法视图
    flask standrad class 使用
    flask add_url_rule的使用
    模板的继承
    模板变量设置 set 和 with
    模版include的用法
  • 原文地址:https://www.cnblogs.com/wugongzi/p/11199300.html
Copyright © 2011-2022 走看看