Re: finding the first non digit character in a string
- From: japhy@xxxxxxxxxxxx (Jeff 'japhy' Pinyan)
- Date: Fri, 28 Oct 2005 10:02:19 -0400 (EDT)
On Oct 28, Bowen, Bruce said:
I see where you can test for a match in a string of data using the If ( ) statement, but can you use it with an 'index' statement?
The index() function is for finding a string in another string. Patterns (regexes) are not allowed.
$DD = "5000|SIHHTEXT"
I've tried $d = index($DD, m/[^\d]/); $d = index($DD, /[^\d]/); $d = index($DD, [^\d]);
You want the location of the first non-digit?
my $non_digit = ($DD =~ /\D/) ? $-[0] : -1; # -1 means not found
(See 'perlvar' for an explanation of $-[0], in the @- array.)
will be or if there will be any cents. I need to extract the dollar / cents out from the text. Any suggestions as to how that can be done?
That's much simpler:
my ($money) = $DD =~ /^(\d+\.?\d*)/;
That will match the numbers at the beginning of the string, optionally allowing for a decimal point (\.) and digits after it.
-- Jeff "japhy" Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated, we who for every service http://www.perlmonks.org/ % have long ago been overpaid? http://princeton.pm.org/ % -- Meister Eckhart .
- References:
- finding the first non digit character in a string
- From: Bruce Bowen
- finding the first non digit character in a string
- Prev by Date: Re: finding the first non digit character in a string
- Next by Date: Re: help slurping a file
- Previous by thread: Re: finding the first non digit character in a string
- Index(es):