50,758
社区成员
发帖
与我相关
我的任务
分享
public static void main( String[] args )
{
List<String> list=new ArrayList<String>();
String [] letters={"a","b","c","d","e","f","g","h","i"};
String test="123edfhi65eedacb";
String[] testArr=test.split( "" );
Pattern reg1=Pattern.compile( "\\d" );
Pattern reg2=Pattern.compile( "[a-z]" );
for(int i=0;i<testArr.length;i++){
Matcher m1=reg1.matcher(testArr[i]);
Matcher m2=reg2.matcher(testArr[i]);
if(m1.matches()){
list.add( letters[(Integer.parseInt( testArr[i] )-1)] );
}
if(m2.matches()){
list.add( (Arrays.binarySearch(letters, testArr[i] )+1) +"");
}
}
System.out.println( list.toString().replaceAll( "[^\\da-z]", "" ) );
}