Right now I have a list of first and Last names, one name per row. Each name is separated by a space, I want to keep the Fist letter of the last name and erase the rest and place a period at the end.
i.e. Tom Smith -> Tom S.
Ron
Select last name except First Initial
Moderator: General Moderators
Re: Select last name except First Initial
Sounds reasonable. What's your question?
Just in case it's "will somebody give me the answer?" then allow me to reply preemptively with "no, but we'll help you if you're having problems with your own attempt at it".
Just in case it's "will somebody give me the answer?" then allow me to reply preemptively with "no, but we'll help you if you're having problems with your own attempt at it".
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Select last name except First Initial
There are several ways to do this. Here is one way: Use strpos() to find the position of space and then substr() to truncate the string.
(#10850)
Re: Select last name except First Initial
Absolutely, I'm not really looking for a hand out I want to understand what I'm doing.
I've tried this
\s\w+\n
But I'm not sure how to start the selection after the space-first character (In the last name).
What I have highlights the space and the last name.
Ron
I've tried this
\s\w+\n
But I'm not sure how to start the selection after the space-first character (In the last name).
What I have highlights the space and the last name.
Ron
Re: Select last name except First Initial
I really would like to do this with Regex if I can.
Ron
Ron
Re: Select last name except First Initial
Regex isn't the best tool for it but whatever.
Start at the space, capture the next non-space character, and read until the end of the string. Replace that with a space and the character you captured.
Start at the space, capture the next non-space character, and read until the end of the string. Replace that with a space and the character you captured.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Select last name except First Initial
substr($name, 0, strpos($name, ' ')+2) . '.'Christopher wrote:There are several ways to do this. Here is one way: Use strpos() to find the position of space and then substr() to truncate the string.
(#10850)