工作中遇到的奇葩需求
package com.hsi.utils;import java.util.Arrays;import java.util.List;public class AddString { private static String qq =""; private static int num=0; /** * 实现字符串+1 * 如ab9Z变为ac0A, * @param a * @return */ public static String returnString (String a) { //判断是否为纯数字 qq = a; try{ Integer pcode = Integer.valueOf(qq).intValue()+1; qq = ""+pcode; }catch(Exception e){ qq = bre(String.valueOf(qq.charAt(qq.length()-1))); } return qq; } public static String bre(String az) { String y[] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}; List list = Arrays.asList(y); for (int k = 0; k < y.length; k++) { if(qq.length()-num<0){ break; } if(az.equals("Z")){ //当等Z的时候,这个时候取的应该是A StringBuffer sb = new StringBuffer(qq); sb.replace(qq.length()-num-1, qq.length()-num, "A"); qq = sb.toString(); num++; qq = bre(String.valueOf(qq.charAt(qq.length()-1-num))); return qq; } else if (az.equals("z")) { StringBuffer sb = new StringBuffer(qq); sb.replace(qq.length()-num-1, qq.length()-num, "a"); qq = sb.toString(); //qq = qq.substring(0,qq.length()-1)+"0"; num++; qq = bre(String.valueOf(sb.toString().charAt(sb.toString().length()-1-num))); return qq; } else if (az.equals("9")) { StringBuffer sb = new StringBuffer(qq); sb.replace(qq.length()-num-1, qq.length()-num, "0"); qq = sb.toString(); num++; qq = bre(String.valueOf(sb.toString().charAt(sb.toString().length()-1-num))); return qq; } else{ if(num > 0){ if(!isNum(String.valueOf(qq.charAt(qq.length()-1-num)))){ StringBuffer sb = new StringBuffer(qq); sb.replace(qq.length()-1-num, qq.length()-num, y[list.indexOf(az)+1]); qq = sb.toString(); } if(isNum(String.valueOf(qq.charAt(qq.length()-1-num)))){ StringBuffer sb = new StringBuffer(qq); int ss = Integer.valueOf(String.valueOf(qq.charAt(qq.length()-1-num))).intValue()+1; sb.replace(qq.length()-1-num, qq.length()-num, ""+ss); qq = sb.toString(); }} else{ StringBuffer sb = new StringBuffer(qq); sb.replace(qq.length()-num-1, qq.length()-num, y[list.indexOf(az)+1]); qq = sb.toString(); } return qq; } } return null; } public static boolean isNum(String str){ return str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$"); } }