• 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 coder

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I have a string ex: "3a4b6c" how would i change/decode the string so it returns as "aaabbbbcccccc"?
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following uses regex to parse the string for numbers and letters:

Probably needs a lot of tweaking to adapt it to your actual requirements (which I do not know)
 
william rapa
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code works excellent. As you said there were a few tweaks necessary. Now to figure out how to achieve the opposite of my OP.
 
T Dahl
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

william rapa wrote:Your code works excellent. As you said there were a few tweaks necessary. Now to figure out how to achieve the opposite of my OP.



Something like this?

I am sure there are more elegant solutions.

May be invoked with:
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

T Dahl wrote:The following uses regex to parse the string for numbers and letters:

Probably needs a lot of tweaking to adapt it to your actual requirements (which I do not know)


You can get rid of the entire "from" variable. Matcher.find() by defaults searches from the last found position.
 
T Dahl
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:You can get rid of the entire "from" variable. Matcher.find() by defaults searches from the last found position.



Good point! I am just learning this now. I have discovered that m.end() will sometimes increment farther than I would expect. E.g.:

will actually count the look-ahead expression, even though it is supposed to be non-capturing. Just have to know that...
 
I can't take it! You are too smart for me! Here is the tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic