zoukankan      html  css  js  c++  java
  • 分割符(split)

    package cn.check.com;
    
    public class RegexDemo {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            String s = "aa,bb,cc";
            String[] sp = s.split(",");// 进行分割
            // 遍历
            for (int x = 0; x < sp.length; x++) {
                System.out.println(sp[x]);
            }
    
            System.out.println("-------------------------------");
    
            String s1 = "aa.bb.cc";
            String[] sp1 = s1.split("\.");// sp1接收数组
            // 遍历
            for (int x = 0; x < sp1.length; x++) {
                System.out.println(sp1[x]);
            }
            System.out.println("---------------------------");
            String s2 = "aa    bb                    cc";
    
            String[] sp2 = s2.split(" +");// 空格+进行分割,不限空格大小
    
            // 遍历
            for (int x = 0; x < sp2.length; x++) {
                System.out.println(sp2[x]);
            }
            System.out.println("----------------------------");
            // 硬盘上的路径
            String s3 = "H:\kinggsoft\kduu_ba";
            String[] sp3 = s3.split("\\");// 一个需要两个\来分割 所以需要四个// 遍历
            for (int x = 0; x < sp3.length; x++) {
                System.out.println(sp3[x]);
            }
        }
    
    }
  • 相关阅读:
    File
    多态
    方法重载
    Math
    instanceof
    强制类型转换
    泛型
    springboot热部署
    iOS bug处理
    iOS8-xcode6中添加pch全局引用文件
  • 原文地址:https://www.cnblogs.com/yschung/p/9290015.html
Copyright © 2011-2022 走看看