• Post Reply Bookmark Topic Watch Topic
  • New Topic

String coder  RSS feed

 
william rapa
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a string ex: "3a4b6c" how would i change/decode the string so it returns as "aaabbbbcccccc"?
 
T Dahl
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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:
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!