fork 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 msg ="BGM+EFD:20:109:GBP+aa:bb:cc+5+dd'CST++KindOfDeclaration+0'";
  13. String bgm=msg.split("\\'") [0];
  14. String tempMessage=bgm;
  15. String messageFunction="56";
  16. System.out.println(bgm);
  17.  
  18. //if(StringUtils.isNotEmpty(messageFunction)){
  19. if(!(messageFunction==null || messageFunction.equalsIgnoreCase(""))){
  20. bgm=bgm.replace(bgm.split("\\+")[3],messageFunction);
  21. }
  22. else{
  23. bgm=bgm.replace(bgm.split("\\+")[3],"9");
  24. }
  25. msg=msg.replace(tempMessage, bgm);
  26. System.out.println(msg);
  27. }
  28. }
Success #stdin #stdout 0.05s 711168KB
stdin
Standard input is empty
stdout
BGM+EFD:20:109:GBP+aa:bb:cc+5+dd
BGM+EFD:20:109:GBP+aa:bb:cc+56+dd'CST++KindOfDeclaration+0'