Advertisement
Guest User

Adding 50 to string numbers

a guest
Aug 3rd, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1.         String str = "Some3people6love20code102";
  2.         String newstr = "";
  3.         String tmp = "";
  4.         for (int i = 0; i<str.length(); i++){
  5.             if((int)str.charAt(i) >= 48 && (int)str.charAt(i) <= 57){
  6.                 tmp += str.charAt(i);
  7.             }else{
  8.                 if(tmp.length()>0){
  9.                     newstr+=((Integer.parseInt(tmp)+50)+"");
  10.                 }
  11.                 newstr+=str.charAt(i);
  12.                 tmp = "";
  13.             }
  14.             System.out.println(newstr);
  15.         }
  16.         if(tmp.length()>0){
  17.             newstr+=((Integer.parseInt(tmp)+50)+"");
  18.         }
  19.         System.out.println(newstr);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement