------ Solution ---------- ----------------------------------
If we say , simply convert the string you give it, It can be processed .
assume that all strings to "String - letters - characters - numbers" such treatment , then, need to be adjusted.
I novice , as follows , and all the great God laughed . ( Also see instructions )
public class ConvertTest {
/**
* java中如何将"我爱你abc我123"转换成"我爱你[Aa][Bb][Cc]我123"
* @author Milo 2013-9-10
* @param args
*/
public static void main(String[] args) {
String s = "我爱你abc我123" ;
System.out.println("Start with : " + s);
String result = myString(s) ;
System.out.println("End with : " + result);
}
public static String myString(String s){
String[] st = new String[]{"我" , "爱" , "你"} ;
StringBuffer sb = new StringBuffer() ;
char[] ch = s.toCharArray() ;
for(char cha : ch){
for(String str : st){
if(String.valueOf(cha).equals(str)){
sb.append(str) ;
}
}
if(cha >=48 && cha <=57 ){
sb.append(Integer.parseInt(String.valueOf(cha))) ;
}
else if(cha >=97 && cha <=122){
sb.append("[") ;
sb.append(String.valueOf((char)(cha - 32))) ;
sb.append(String.valueOf(cha)) ;
sb.append("]") ;
}
}
return sb.toString() ;
}
}
//结果:
//Start with : 我爱你abc我123
//End with : 我爱你[Aa][Bb][Cc]我123
------ Solution ------------------------------------- -------
landlord just put lowercase becomes [ uppercase + lowercase ] do
String str = "我爱你abc我123";
StringBuilder sb=new StringBuilder();
for(int i=0;i<str.length();i++){//循环字符串
char c=str.charAt(i);
if(Character.isLowerCase(c)){//当碰到小写的时候变成[大写+小写]
sb.append("["+Character.toUpperCase(c)+c+"]");
}else{//其它情况直接添加
sb.append(c);
}
System.out.println(sb.toString());
------ For reference only ----------------------------------- ----
java how to "I love you my 123 abc " into "I love you [Aa] [Bb] [Cc] I 123"
------ For reference only - --------------------------------------
java how to "I love you abc I 123 "into" I love you [Aa] [Bb] [Cc] I 123 "
------ For reference only ----------------- ----------------------
search string, and then replace the abc [Aa] [Bb] [Cc]
---- - For reference only ---------------------------------------
; and I know so dry , singles I do not know how to write , you can write a demo I see no
------ For reference only ------------ ---------------------------
I suggest not to use assic code conversion, because some Chinese characters also in the case of ASSIC code value intermediate
------ For reference only ---------------------------- -----------
I suggest not to use assic code conversion, because some Chinese characters will be in the middle of sensitive aSSIC code value
Thank pointing. However, I was also the first time I heard the Chinese characters in the ASCII code of the intermediate case . Detailed few examples can do ? Thank you !
没有评论:
发表评论