Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

alphanumeric - finding one less!

Posted on 2002-05-08
4
Medium Priority
?
202 Views
Last Modified: 2010-03-05
Hi

I need some help to chamge the end character in a string of letters to the character or number which is one less based on alphanumeric characters and maintaining case

example string 1 - " /YEZ/NOZ1/B2FREE/fixed "
example string 2 - " /YEZ/NOZ1/B2FRE3/fixed "

I want to become

example string 1 - " /YEZ/NOZ1/B2FRED/fixed "
example string 2 - " /YEZ/NOZ1/B2FRE2/fixed "

I have tried using "$string =~ s/$end/$end -1/"

but it doesn't work becase it is not a number and sometimes it finishes with "a letter/fixed" sometimes "a number/fixed"

"fixed" is the known string which is always constant...
"/APHANUM/APHANUM/APHANUM/" is the dynamic bit and it is always the character before "/fixed" that I need to be one less...

Can anyone tell me how to do it?

thanks

Jilly  
0
Comment
Question by:jillybabe
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
holli earned 400 total points
ID: 6996554
this is one way:

$b="/YEZ/NOZ1/B2FREE/fixed";
$a="/YEZ/NOZ1/B2FRE3/fixed";

$a=~s|(.{1})/fixed|chr(ord($1)-1).'/fixed'|e;
$b=~s|(.{1})/fixed|chr(ord($1)-1).'/fixed'|e;

print "$a\$b";


regards,

holli
0
 
LVL 1

Expert Comment

by:japhyRPI
ID: 6998068
What should "BAA" decrease to?  "AZZ"?  And how about "FR0"?  That's a zero, so should it be "FQ9"?  We need more assistance with these boundary cases.  It's far easier to INCREMENT than to decrement.
0
 

Author Comment

by:jillybabe
ID: 6998242
Great that did it !

Thanks holli and you too japhyRPI

Jilly
0
 
LVL 1

Expert Comment

by:japhyRPI
ID: 6998715
Jilly, I'm just warning you that the current response turns "BAA" into "BA@", "FR0" into "FR/", and "STa" into "ST`".  To overcome these situations, you're going to need a slightly different regex.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question