Re: How to extract digits by position in a string?
- From: chas.owens@xxxxxxxxx (Chas. Owens)
- Date: Wed, 9 Apr 2008 16:51:57 -0400
On Wed, Apr 9, 2008 at 4:31 PM, Jialin Li <jialinli1981@xxxxxxxxx> wrote:
substr($string,0,2) will give you the first two digitssnip
substr($string,5,1) will give you the sixth digit.
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.
.
- Follow-Ups:
- Re: How to extract digits by position in a string?
- From: Gunnar Hjalmarsson
- Re: How to extract digits by position in a string?
- From: Jialin Li
- Re: How to extract digits by position in a string?
- References:
- How to extract digits by position in a string?
- From: Michael Barnes
- Re: How to extract digits by position in a string?
- From: Jialin Li
- How to extract digits by position in a string?
- Prev by Date: Re: not grep
- Next by Date: Re: not grep
- Previous by thread: Re: How to extract digits by position in a string?
- Next by thread: Re: How to extract digits by position in a string?
- Index(es):
Relevant Pages
|