• Post Reply Bookmark Topic Watch Topic
  • New Topic

String parsing algorithm  RSS feed

 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a database table that contains a comments column with a 4000 char limit. I want to write an algorithm that can take a variable length comment String (for example 10,000 chars) and break it up into multiple comment records. The database part is easy, its the dynamic parsing of the comment String into multiple Strings. Did I mention I also need to make sure that each comment does not end in the middle of a word, so that means space separated. If anyone has any pseudo code or ideas or knows of any libraries or utils please let me know!

Thanks!
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37395
531
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy,
Could you use a regular expression to do this? I'm thinking a regular expression that is up to 4,000 characters and ends with either a whitespace character or the end of the string.
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a lot of ways this could be done. The pros seem to prefer regex, personally I find regex can be tricky to implement, but that's just me. If you have a lot of parsing to do regex is probably most efficient.

 
fred rosenberger
lowercase baba
Bartender
Posts: 12559
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
simple brute force might work, too.

Go to position 4000. is it a space? then go to 3999. is it a space? etc...

when you find a space as position X, get substring from 0 to X.

Then go to X + 4000, and repeat.

(note: I may not have my fenceposts exactly right, but you get the idea, I hope).
 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys.. I appreciate the help!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!