MySQL Forums
Forum List  »  Newbie

Re: return string after the first space
Posted by: Peter Brawley
Date: July 26, 2015 10:44PM

> I still need help so it only displays the phone number after the 1st space

Think it through: if the number has a space, you need just the digits after that space, ie if phonenumber= 02 5333 1111, you need the digits starting at 1 + locate(' ','02 5333 1111'), ie substr( '02 5333 1111', 1 + locate(' ','02 5333 1111') ). If there's no space, locate(' ',num_with_no_spaces) returns 0, 1+0=1, so the same formula works for a number with no spaces. So your answer is ...

substr( phonenumber, 1 + locate(' ',phonenumber) )

But it's usually a mistake to make your number parsing contingent on the user having applied predictable spacing. Better to remove the spaces and use the telephone company's rules for parsing the resultant number.



Edited 2 time(s). Last edit at 07/26/2015 10:48PM by Peter Brawley.

Options: ReplyQuote


Subject
Written By
Posted
Re: return string after the first space
July 26, 2015 10:44PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.