Solved

alphanumeric - finding one less!

Posted on 2002-05-08
4
154 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 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Great that did it !

Thanks holli and you too japhyRPI

Jilly
0
 
LVL 1

Expert Comment

by:japhyRPI
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now