Re: Replacing first character in a string

From: Date: Wed, 30 Apr 2003 20:29:45 +0000
Subject: Re: Replacing first character in a string
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-145856@lists.php.net to get a copy of this message
In one line: $rawPOINTS[0]=(substr($rawPOINTS[0],0,1)==','?'0'.substr($rawPOINTS[0],1):$rawPOINTS[0]) On Wednesday, April 30, 2003, at 04:03 PM, Lee P. Reilly wrote:
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 -- Brent Baisley Systems Architect Landover Associates, Inc. Search & Advisory Services for Advanced Technology Environments p: 212.759.6400/800.759.0577


« previous php.general (#145856) next »