Re: Re: Replacing first character in a string
| From: | Weston Houghton | Date: | Thu, 01 May 2003 04:02:51 +0000 |
| Subject: | Re: Re: Replacing first character in a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-145889@lists.php.net to get a copy of this message | ||
Why not just reference the character directly and test against that? It's not much different, but I would guess that it is slightly faster.
if ($str{0} == ",") {
$str{0} = 0;
}
Wes
On Wednesday, April 30, 2003, at 11:20 PM, Hugh Bothwell wrote:
"Lee P. Reilly" <lreilly@lanl.gov> wrote in message news:3EB02C14.79845983@lanl.gov...--------------------------------------------------------------------------- The selection and placement of letters on this page was determined automatically by a computer program. Any resemblance to actual words, sentences, or paragraphs is pure coincidence, and no liability will be assumed for such coincidences. ---------------------------------------------------------------------------I wonder if anyone can help me? I have a string something like this: ",.00109863,.00219725,.00329588.... and so on....". If the *first character* in the string is a comma (as in the case above) then I want to replace it with "0,", but I cannot find a way to do it.Of all the replies, only one was correct, and it was pretty obfuscated. Try this: if (substr($str,0,1) == ",") $str = "0" . substr($str,1); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php