-2

I have 1 string with the following format: {1:F01BFTVVNVXAXXX1695221420}{2:O4502103200608PNBPUS33CPHL20769045012006090803N}{4: :25:2000191044834

:20:41565330

:21:000001106

:30:200608

:32A:200612USD657316,00

:52D:BCH:YOUR HEAD OFFICE

:20:41565331

:21:000001107

:30:200608

:32A:200612USD525099,59

:52D:BCH:YOUR HEAD OFFICE

:20:41565331

:21:000001107

:30:200608

:32A:200612USD55200

:52D:BCH:YOUR HEAD OFFICE

:20:41565331

:21:000001107

:30:200608

:32A:200612USD2500

:52D:BCH:YOUR HEAD OFFICE

-}

It has many fields: 32A: [value] with different values. How to cut these fields and save them to a list using java code?

  • _How to cut these fields and save them to a list using java code?_ – What have you tried? What have you researched? Please clarify your problem in doing that based on your own coding attempt; see also [How to Ask a Good Question](https://stackoverflow.com/help/how-to-ask) as well as the [Stack Overflow question checklist](https://meta.stackoverflow.com/q/260648/5698098). – Ivo Mori Jul 16 '20 at 05:19
  • _As a hint_: I'd solve this using a [regular expression](https://stackoverflow.com/q/4736/5698098); have a look at this existing Q/A [Getting the text that follows after the regex match](https://stackoverflow.com/q/5006716/5698098). – Ivo Mori Jul 16 '20 at 06:24

1 Answers1

0

Assuming that you have an array of these strings and you only want to save the values after "32A" into an ArrayList:

ArrayList<String>saved=new ArrayList<>();

public void cutAndSave(String[] codes){
for(int i=0;i<codes.length;i++){
 if(codes[i].contains("32A"){
String cutted[]=codes[i].split(":")
 }else{
  continue;
 }
for(int y=0;y<cutted.length;y++){
   if(!cutted[y].equals(""))
   saved.add(cutted[y]);
}
}
while(list.remove("32A")){}
}