Re: How to extract digits by position in a string?



On Wed, Apr 9, 2008 at 4:31 PM, Jialin Li <jialinli1981@xxxxxxxxx> wrote:
substr($string,0,2) will give you the first two digits
substr($string,5,1) will give you the sixth digit.
snip

There are at least three downsides to using the substr function:
1. multiple function calls
2. lots of typing
3. no guarantee that the input string is in the right format

The substr function is useful, but regexes and the unpack function are
much better for most cases. One case where the substr function is
better than a regex is the extraction of a substring from the end of a
string which may have a variable length (i.e. fixed length regexes
that are anchored only at the end of the string).

--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
.



Relevant Pages

  • Re: Missing removeStr and substr function
    ... (removestr and the substr function) ... but to answer my book questions I miss the substr and removestr ... pointers. ... the end of each string and it terminates the string. ...
    (comp.lang.c)
  • RE: Urgent :search and replace
    ... Try using split function ... Try using substr function ... Substr($string to search, <number of character from where to start),<end of ... The problem with the string is broken in the differenet line. ...
    (perl.beginners)
  • Re: How to extract digits by position in a string?
    ... lots of typing ... The substr function is useful, but regexes and the unpack function are ... string which may have a variable length (i.e. fixed length regexes ...
    (perl.beginners)
  • Re: selecting range of chars from a string?
    ... I have a string that has a 3 char offset and an 8 char ... System verilog will have substr function. ...
    (comp.lang.verilog)