/*
*@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
诗语江南 阅读(3421)
评论(3) 编辑 收藏