public static List < String > splitFixedText ( final List < ColumnMetaData > columnMetaData , final String lineToParse , final boolean preserveLeadingWhitespace , final boolean preserveTrailingWhitespace ) { final List < String > splitResult = new ArrayList <> ( ) ; int recPosition = 1 ; for ( final ColumnMetaData colMetaDataObj : columnMetaData ) { String tempValue = lineToParse . substring ( recPosition - 1 , recPosition + colMetaDataObj . getColLength ( ) - 1 ) ; recPosition += colMetaDataObj . getColLength ( ) ; // make sure that we preserve leading and trailing spaces as user has requested // This was previously issuing a trim() if ( ! preserveLeadingWhitespace ) { tempValue = ParserUtils . lTrim ( tempValue ) ; } if ( ! preserveTrailingWhitespace ) { tempValue = ParserUtils . rTrim ( tempValue ) ; } splitResult . add ( tempValue ) ; } return splitResult ; }
Splits up a fixed width line of text