字符串截取

一、字符串操作

1、字符串截取

//1、含头不含尾:
zrjoutstandingtreaty.getTreatyid().substring(0,2)

//2、截取最后一位:
"Q".equals(treatyLists.getAccperiod().substring(treatyLists.getAccperiod().length()-1))

2、获得指定长度的随机字符串

public static String getRandString(int maxLength){
    String source ="abcdefghijklmnopqrskuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    StringBuffer sb = new StringBuffer();
    Random rand = new Random();
    for(int i=0;i<maxLength;i++){
        sb.append(source.charAt(rand.nextInt(source.length())));
    }
    return sb.toString();
}

3、取整

//总条数
String totalCount = "7";
//每页大小
String perPage = "6";
//向上取整用Math.ceil(double a)
//向下取整用Math.floor(double a)
//最小页码
int min = 1;
//最大页码
int max = (int)Math.ceil((double)Integer.parseInt(totalCount)/Integer.parseInt(perPage));
//定义随机数
Random random = new Random();

//随机取一页
int pageNo = random.nextInt(max)%(max-min+1) + min;
System.out.println(pageNo);

 

字符串截取

上一篇:WinPE启动U盘的制作方法与软件下载(通用PE工具箱/老毛桃/大白菜WinPE)


下一篇:Windows 8 键盘上推自定义处理