Solved

How to inc or dec a string like "j000012.html"

Posted on 2003-11-19
14
260 Views
Last Modified: 2013-12-25
I have a simple question, I want to inc or dec string, for example, "j000012.html" to "j000011.html" or "j000013.html".
0
Comment
Question by:mikezang
  • 7
  • 6
14 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 9783766
Depends what language you are talking about.  What's your preference?


0
 
LVL 5

Author Comment

by:mikezang
ID: 9783837
Sorry, that is Perl.
0
 
LVL 84

Expert Comment

by:ozo
ID: 9785133
$string = "j000012.html";
substr($string,1,6)++;
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 84

Expert Comment

by:ozo
ID: 9785143
$string =~ s/(\d+)/my $i=$1;++$i/e;
0
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 9785186
Decrement is a little trickier
(what would "j000000.html"  be when decremented?)

string = "j000012.html";
for( substr$string,1,6 ){
     tr/0-9/9876543210;
    $_++;
    tr/0-9/9876543210/;
}
0
 
LVL 5

Author Comment

by:mikezang
ID: 9785204
Thanks a lot!
0
 
LVL 5

Author Comment

by:mikezang
ID: 9786822
Hi
Itried $string =~ s/(\d+)/my $i=$1;++$i/e;
it's ok, but when I tried $string =~ s/(\d+)/my $i=$1;--$i/e;
I only got "j11.html", not "j000011.html", can you help me again?
0
 
LVL 5

Author Comment

by:mikezang
ID: 9788110
Then if $string = "gs19/j000012.html", it also doesn't qork.
Can you help me?
0
 
LVL 84

Expert Comment

by:ozo
ID: 9791965
As I said, decrement is a little trickyer.
You could try something like

$string =~ s/(\d+)(\.html)/my $i=$1;$i=~tr!0-9!9876543210!;++$i;$i=~tr!9876543210!0-9!;$i.$2/e;

or did you want to decrement both the 19 and the 000012?
0
 
LVL 5

Author Comment

by:mikezang
ID: 9792164
No, I only want to inc or dec filename, not directory.
0
 
LVL 84

Expert Comment

by:ozo
ID: 9792380
what identifies the part you want to inc or dec?
0
 
LVL 5

Author Comment

by:mikezang
ID: 9795004
$file = "gs19/j000003.html" or "qjs/j00003.html" or "....../xxx0003.html"

I hope
$prev = "gs19/j000002.html" or "qjs/j00002.html" or "....../xxx0002.html"
$next = "gs19/j000004.html" or "qjs/j00004.html" or "....../xxx0004.html"

0
 
LVL 84

Expert Comment

by:ozo
ID: 9795107
If it's always 6 digits .html then
($next = $file) =~ s/(\d{6})(\.html)/sprintf"%06d$2",$1+1/ie;
($prev = $file) =~ s/(\d{6})(\.html)/sprintf"%06d$2",$1-1/ie;
0
 
LVL 5

Author Comment

by:mikezang
ID: 9795536
Thanks a lot!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unable to run an exchange 2010 powershell script from Task Scheduler 11 120
disabled AD accounts info 3 76
need a quick help to fix the script logic 4 71
ROBOFTP UNZIP 1 46
In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

803 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