• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String correction

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"johnnysss smithxxxx and Drop Bear,"

Welcome to JavaRanch! Please check your private messages by clicking on My Private Messages. Thanks!
 
johnny s smith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
done!!! :-)
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic