zoukankan      html  css  js  c++  java
  • 字符串用法

    package zhiZuo4;
    
    public class Test {
    
        public static void main(String[] args)
        {
            
            //声明定义字符串
            String A = "AAAAAA";
            String B = null;
            B = new String();
            B = new String("AAAAA");
            char[] c = new char[]{'A','A','A'};
            String D = new String(c);
            System.out.println("字符串D长度为"+D.length());
            System.out.println("字符串D为"+D);
            //查找字符或字符串
            int E = D.indexOf("AA");
            System.out.println(E);
            int F = D.indexOf("B");
            System.out.println(F);
            String G = "hdiasdkaenfklajksj";
            int la = G.lastIndexOf("s");
            System.out.println(la);
            //截取字符或字符串
            String H = G.substring(5);
            System.out.println(H);
            String J = G.substring(5, 6);
            System.out.println(J);
            //去除前后空格
            String K = " hu g t eyd ";
            System.out.println(K.trim());
            //查找替换
            System.out.println(K.replace(" ", ""));
            String L = "WWW,WWW,钱已经花光!";
            System.out.println(L.replaceFirst("WWW", "穷死了"));
            //判断字符串的开始和结束
            System.out.println(L.startsWith("W"));
            System.out.println((L.indexOf("W")==0));
            System.out.println(L.endsWith("!"));
            //判断字符串是否相等
            String a = new String("aBc");
            String b = new String("aBc");
            System.out.println((a==b));
            System.out.println((a.equals(b)));
            //大小写转换
            System.out.println(a.toUpperCase());
            System.out.println(b.toLowerCase());
            //字符串分割
            String a2 = "a b c d e f";
            String[] a3 = a2.split(" ");
            for (int i = 0;i<a3.length;i++)
            {
                System.out.print("	"+a3[i]);
            }
        }
    
    }
  • 相关阅读:
    测试发帖
    C# 四舍五入算法(转)
    赚钱,爱好,生活
    c# 当前dll目录
    BlogWriter
    调用com+时,提示 0x800706f7,error msg:占位程序接收到错误数据,(本地调用时提示:不支持此接口)
    测试2
    系统架构设计 & 避免循环引用(转载)
    Visual Studio 2008查找替换用的正则
    Myeclipse webinf/lib包加载问题
  • 原文地址:https://www.cnblogs.com/youshashuosha/p/5052919.html
Copyright © 2011-2022 走看看