/*
*@author 詩語江南
*@function 將字符串反序輸出(測試形如"My name is 天才"的字符串,反序后為"才天 is name My")
*@parameter 要反序的字符串
*@return 反序后的字符串
*/
public static String rev(String num){
String[] nums = num.split(" ");
StringBuffer sb = new StringBuffer();
for(int i = nums.length-1; i>=0; i--){
StringBuffer sb2 = null;
if(nums[i].length() > 1){
if(isContainZh(nums[i])){
sb2 = new StringBuffer(nums[i]);
sb2.reverse();
}
}
if(sb2 != null)
nums[i] = sb2.toString();
sb.append(nums[i] + " ");
}
return sb.toString();
}
//判斷一個字符串是否有漢字
public static boolean isContainZh(String str){
boolean b = false;
if(str.length() > 1){
byte[] bs = str.getBytes();
if(bs.length != str.length()){
b = true;
}
}
return b;
}
posted on 2007-09-24 01:27
詩語江南 閱讀(3445)
評論(3) 編輯 收藏