Re: Replacing first character in a string
| From: | Michael Lewis | Date: | Thu, 01 May 2003 01:10:56 +0000 |
| Subject: | Re: Replacing first character in a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-145883@lists.php.net to get a copy of this message | ||
Lee,
Try:
if (substr($rawPOINTS,0,1)==",") { substr($rawPOINTS,0,1)="0"; }
It's obvious and unglamorous, but it does the trick.
Michael Lewis
----- Original Message -----
From: "Lee P. Reilly" <lreilly@lanl.gov>
To: "PHP" <php-general@lists.php.net>
Sent: Wednesday, April 30, 2003 4:03 PM
Subject: [PHP] Replacing first character in a string
> Hi there,
>
> 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.
> E.g. say the above string is called $rawPOINTS, what would be in the
> body of the if loop below to replace the comma?
>
> if ($rawPOINTS[0] == ",")
> {
> // hmmmm....
> }
>
> I can think of a few long winded ways of do it, but are there any "one
> liner" string manipulation functions I can use? I shall look into
> regular expressions, but if anyone could tell me the solution I'd
> appreciate it ;-)
>
> - Thanks,
> Lee
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>