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
• Liutauras Vilda
• Paul Clapham
Sheriffs:
• paul wheaton
• Tim Cooke
• Henry Wong
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Piet Souris
Bartenders:
• Mike London

# How do I find Consecutive Letters?

Greenhorn
Posts: 23
• Number of slices to send:
Optional 'thank-you' note:
Sorted String İnput: 1, 2, 2A, 2B, 2C, 3, 3A, 4, 5, 6, 32C, 32D, 50, 51/1, 51/2, 60, 61, 62, 200-2E, 200-2F, 200-2G, 200-2H, 201C, 201/21P, 201/21R, 201/21S,300,300A,301-2A, 542/2K, 542/2L,583-1, 583-585D, 583-585E, 605, 605A, 605B,605C 800A.
Question is about merging consecutive values into a range. E.g.4,5,6 =[4-6] , 2A, 2B, 2C are consecutive values, so range is 2[A-C]. No other values can be in a range.
• General pattern: number[chars][A-Z]
If chars is present, then they have to be equals() to be in a sequence. If the trailing letter is present, they have to be consecutive to have a sequence
A sequence is then abbreviated using: first + "-" + last
51/1, 52/1, 53/1 ==> not merged
51/1A, 51/1B, 51/1C ==> 51/1[A-C]
51/1A, 52/1B, 53/1C ==> [51-53]/1[A-C]
It should be listed as follows.

output:
1
2
2[A-C]
3
3A
[4-6]
32[C-D]
50
51/1
51/2
[60-62]
200-2[E-H]
201C
201/21[P-S]
300
300A
301-2A
542/2[K-L]
583-1
583-585[D-E]
605
605[A-C]
800A

output= merged: [1, 2, 2A, 2B, 2C, 3, 3A, [4-6], 32C, 32D, 50, 51/1, 51/2, [60-62], 200-2E, 200-2F, 200-2G, 200-2H, 201C, 201/21P, 201/21R, 201/21S, 300,300A,301-2A,542/2K, 542/2L,583-1, 583-585D, 583-585E, 605, 605A, 605B,605C 800A]