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?
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.
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 ]
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!
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.