fork(5) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String barcode = "35151022986022000105590000400630036591770797|20151013131745|21.26|";
  13.  
  14. String[] resp = barcode.split("\\|");
  15.  
  16. String cnpj = resp[0].substring(6, 20); //são 14 digitos, iniciado da posicao 7
  17.  
  18. String coo = resp[0].substring(31, 37); // supondo que tenham sempre 6 digitos
  19.  
  20. String data = resp[1].substring(0, 8); // 8 primeiros digitos sao da data
  21.  
  22. String total = resp[2];
  23.  
  24. System.out.println(cnpj);
  25. System.out.println(coo);
  26. System.out.println(data);
  27. System.out.println(total);
  28. }
  29. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
22986022000105
003659
20151013
21.26