aspose file tools*
The moose likes Beginning Java and the fly likes String correction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String correction" Watch "String correction" New topic
Author

String correction

johnny s smith
Greenhorn

Joined: Apr 21, 2008
Posts: 3
i have a string "1234567891011121415....100000"
I need to correct it by inserting the missing numbers, like 13 in the above case. The string can be very huge and has no delimiters. How do you think i should go about doing this?
Joseph Macer
Ranch Hand

Joined: Apr 20, 2008
Posts: 63
If the numbers are in a specific order like that, you could use an int (or your own logic) to keep track of what number you expect next. Then reading in the next X digits to see if it IS that expected number would be pretty easy.
johnny s smith
Greenhorn

Joined: Apr 21, 2008
Posts: 3
well i know this solution but imagine the number of comparisons? i would need to make...coz this sequence could end at a crore or 100 crores or even more. i need something smarter!
[ April 21, 2008: Message edited by: johnnysss smithxxxx ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Welcome to the Ranch, both of you.

Drop Bear? Is that a real name?

But whatever his name, he is probably correct. If you really have a String of concatenated numbers like that, then a linear search is probably the easiest way to insert it.
You will probably have to use the methods of the Integer class like toString(int i) to get the next String to look for; you can use the length of that String to increment a counter variable, so you can work out where to insert the values in a StringBuilder object. Also (if you know there is one number missing) you can have a boolean variable which tells whether you still have anything to insert; when you have inserted it you can stop your iteration. You are unlikely to have a 100-crore number; remember that is several gigaBytes on disc!
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3689
    
  16
Originally posted by Campbell Ritchie:
Drop Bear? Is that a real name?


You have doubts about Drop Bear being a real name, but not johnnysss smithxxxx


Joanne
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
There are so many people called John Smith that there are bound to be collisions and people have to distinguish themselves from previous members with similar namessssssssssssssssssssssssssssssssssssssssss.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

"johnnysss smithxxxx and Drop Bear,"

Welcome to JavaRanch! Please check your private messages by clicking on My Private Messages. Thanks!


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
johnny s smith
Greenhorn

Joined: Apr 21, 2008
Posts: 3
done!!! :-)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Originally posted by johnny s smith:
done!!! :-)


Well done. I presume that means you have got the insertions into your String working. Please tell everybody how you did it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String correction