Hi All
Apologies in advance if this is a dumb question.
I'm trying to separate out digits from an alphanumeric string and then load these into an array using the following.
E.g $string = 1test123
@stringdigits = split(/\D/, $string);
What I wanted to happen was that only the 1,2,3,4 were read and they were separately loaded into the array as:
$stringdigits[0], $stringdigits[1], $stringdigits[2], $stringdigits[3]
What seems to be happening is that the letters are being loaded into the array as empty elements and the numbers are not being separated as I expected. I know strings can be separated into individual characters using:
@indivchars = split(//, $string);
Do I need to somehow combine the two? What am I doing wrong?
Any help would be much appreciated.
Thanks
J
Apologies in advance if this is a dumb question.
I'm trying to separate out digits from an alphanumeric string and then load these into an array using the following.
E.g $string = 1test123
@stringdigits = split(/\D/, $string);
What I wanted to happen was that only the 1,2,3,4 were read and they were separately loaded into the array as:
$stringdigits[0], $stringdigits[1], $stringdigits[2], $stringdigits[3]
What seems to be happening is that the letters are being loaded into the array as empty elements and the numbers are not being separated as I expected. I know strings can be separated into individual characters using:
@indivchars = split(//, $string);
Do I need to somehow combine the two? What am I doing wrong?
Any help would be much appreciated.
Thanks
J