Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Parse a TEXTAREA

  Asked By: Danielle    Date: Feb 16    Category: Java    Views: 1470
  

I have a Java program reading through a TEXTAREA that can be up to
14,000 bytes. I need to parse out the lines that they have entered,
and preserve the spacing as they entered it. The lines are to be
written to a 70 byte CHAR column in a DB2 table. If they hit ENTER
at the end of each line I can look for "\n" and substring everything
in front of it with no problem. The issue is what if they have a
blank line in between two valid lines i.e:

There is no "\n" at the end of the "space" line, so if I use:


int indexForTxt = -2; //prime as -2 so substring will work correctly
String aTxtLine;
for(int i=0;i < numOfLinesInt; i++) {
int lineLength = (ht.get("TXT").toString().indexOf("\n",
(indexForTxt + 2)) - 2);
if (indexForTxt < 0) //related to the initial value of
indexForTxt being negative
indexForTxt = 0;
aTxtLine = ht.get("TXT").toString().substring(indexForTxt,
lineLength);
}
theTxtLines.add(aTxtLine);
theTxtLines.add(i, aTxtLine);
indexForTxt = indexForTxt + (lineLength +2);
}




then I get aTxtLine that is well over 70 bytes. I can't just
subtract 70 from it because the line after the space line may only be
20 bytes and the spacing needs to be preserved. Anyone ever done
anything like this?

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Parse a TEXTAREA Or get search suggestion and latest updates.




Tagged: