Are there any java string function that I can use together with some form of config driven configuration that anyone can suggest?
Well there is the obvious one: the 'substr' method of the String class.
Your 'config' would be the list of start/end or start/length values for each of the components.
The usual parsing issue is knowing how to determine when one element ends and the next one starts. For this fragment of yours:
How do you know if the first component, 'ch_code', is '1', '2', or '122'?
I'd rather suggest regular expressions:
The biggest Problem I see is: how do you know what string comes next?
the sequence of the elements is predefined. I hope I understand your question correctly.
I will explore towards the substr function. Thank you for the suggestion.
the input will be 1 string at a time, it will not have cases of 2 strings concatenated. I will look at the regex that is suggested. Thank you for the advise.
the input will be 1 string at a time, it will not have cases of 2 strings concatenated.
this does not solve the problem (for me as a casual bystander): how do you know what kind of string comes next...
Hi, I am inclined to think that the configuration you have mentioned initially can work well. Also you might want to put a flag after Presenter in config marking when the repetition starts. As suggested by few others as well go with substr to keep things simple.
Here I would extract header data in a sequence of substr's until I see the flag and then run a loop till the end of the input string (I am assuming that the length of field in every record is same).