thieumao

Tách số trong chuỗi

Aug 4th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.40 KB | None | 0 0
  1. public class tachso {
  2.  
  3.     /**
  4.      * @param args
  5.      */
  6.     public static void main(String[] args) {
  7.         String str = "leo13linh07 tinh1992";
  8.         str = str.replaceAll("\\D", " ");
  9.         str = str.trim();
  10.         str = str.replaceAll("( )+", " ");
  11.  
  12.         String[] result = str.split(" ");
  13.         for (int i = 0; i < result.length; i++) {
  14.             System.out.print(result[i] + "; ");
  15.         }
  16.  
  17.         System.out.println("\nresult:" + str);
  18.     }
  19.  
  20. }
Advertisement
Add Comment
Please, Sign In to add comment