java - Parsing String with fixed-width fields but different length -
i need parse long string pattern:
1)'*' (text,len:1) 2)accountcount (number,len:2) 3)accountnumber1 (text,len:20) 4)accountnumber2 (text,len:20) 5)accountnumber3 (text,len:20) 6)accountnumber4 (text,len:20) ... ?)accountnumber'$accountcount' (text,len:20) ?)'^' (text,len:1)
as can see, accountnumber field repeated in 'accountcount' times.
what best way declare class string
, set accountcount,accountnumber1,accountnumber2,accountnumber3,...
properties?
using guava splitter
.
final string in = "* 3 accountnumber1 accountnumber2 accountnumber3^"; final iterable<string> accounts = splitter.fixedlength(20).trimresults().split(in.substring(3, in.length - 1);
something that. can "transform" accounts
list
of account
object if needed.
Comments
Post a Comment