Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to strip off the last word in this string?

Status
Not open for further replies.

hujirong

Technical User
Aug 22, 2005
13
CA
Hi All

Not a Perl programmer but have to write something. How to take out the last word "WebLinks_docs" from the following string? Thanks a lot.

Jirong

C:\ClearCase\ss_view\Prod\jihu_WebLinks_Mainline\Playground_apps_sub\WebLinks_docs
 
Code:
$str = "C:\\ClearCase\\ss_view\\Prod\\jihu_WebLinks_Mainline\\Playground_apps_sub\\WebLinks_docs";
$str = substr ( $str, rindex ( $str, "\\" ) + 1 );
print "$str\n";
 
Then how to transfer from
C:\ClearCase\ss_view\Prod\jihu_WebLinks_Mainline\Playground_apps_sub\WebLinks_docs

to

C:\\ClearCase\\ss_view\\Prod\\jihu_WebLinks_Mainline\\Playground_apps_sub\\WebLinks_docs

Really not a programmer, thanks a lot.
Jirong
 
$str = 'C:\ClearCase\ss_view\Prod\jihu_WebLinks_Mainline\Playground_apps_sub\WebLinks_docs';
@tmp = split /\\/, $str;
pop @tmp;
$str = join('\\', @tmp);
print "$str\n";

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top