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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Value between two points.

Status
Not open for further replies.

kb0rhe

Technical User
Dec 25, 2006
16
US
How do I get a value between two points on a line?

"BRG CALIF. 2 STAR 0000 00000000"


Point "A" is "BRG" point "B" is "0000"

I want to see everything between the "G and 0"
Less "G" and "0".

So what should be returned " CALIF. 2 STAR "

I can strip the spaces out myself.

The reason I can't use array. (Or think I can't) is because I don't know what might be in between those two points at any given time.

Douglas
 
Okay I am dumb I could use substr and count backwards. I will post my code.
Douglas
 
Try a regular expression:

Code:
my $str = "BRG  CALIF. 2 STAR             0000 00000000";
my ($value) = $s =~ /BRG(.*?)0000/;

 
If it's always a static length, use...
$line = "BRG CALIF. 2 STAR 0000 00000000";
$val = substr($line,3,28);
print "$val\n";

For variable length as long as it starts with XXX and ends with XXXXxXXXXXXXX...
$line = "BRG CALIF. 2 STAR 0000 00000000";
$linelen = length($line);
$val = substr($line,3,$linelen-16);
print "$val\n";

Or go with the regex...
$line = "BRG CALIF. 2 STAR 0000 00000000";
$line =~ m/\s(.*)\s\s/;
print "$1\n";

Mark

 
my $line='BRG calif. etc 0000 00000';

my $one='BRG';
my $two='0000 ';

$a=~/$one(.*)$two/;

print $1 if($1);

Note that my $two has a space after these zeroes. If there would be just 0000 (and no space after them) than the regexp consider as 0000 (your point B) the final 0000 of $line.

Anca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top