#!/usr/bin/perl use warnings; use strict; my $str0 = "C:/Build~~/Win/App/Experiments/1_0/"; my $str1 = "${str0}Experiments/Blood Pressure/_pieces"; my $str2 = "${str0}temp/Blood Pressure/_pieces"; ($str0 ^ $str1) =~ /^\0*/; my $commonLen = $+[0]; my $commonStr = substr $str1, 0, $commonLen, ""; substr $str2, 0, $commonLen, ""; print "Common: $commonStr\n"; print "Tail 1: $str1\n"; print "Tail 2: $str2\n";
Output:
Common: C:/Build~~/Win/App/Experiments/1_0/ Tail 1: Experiments/Blood Pressure/_pieces Tail 2: temp/Blood Pressure/_pieces
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Remove a common prefix from two strings
by polettix (Vicar) on Aug 05, 2005 at 02:09 UTC | |
by GrandFather (Saint) on Aug 05, 2005 at 02:26 UTC | |
|
Re: Remove a common prefix from two strings
by blazar (Canon) on Aug 05, 2005 at 09:36 UTC |