Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Another question regarding string variables
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Another question regarding string variables
Date
Thu, 28 Feb 2013 09:28:15 +0000
Some more explanation might be wished.
First off, there is a tacit assumption here that the name has been
trimmed of leading and trailing spaces.
Use -trim()- first, therefore.
Second, the logic is that if the last word is a single character, then
the previous character is a space. So we look for a space as the
penultimate (one before last) character of a name.
Note that
replace fullname = subinstr(substr(fullname, -2, 2), "", 1) if
substr(fullname, -2, 1) == " "
is _not_ the way to do it as can be seen from
. local foo "John Anthony A"
. di subinstr("`foo'", substr("`foo'", -2, 2), "", 1)
Johnnthony A
Nick
On Thu, Feb 28, 2013 at 8:20 AM, Nick Cox <[email protected]> wrote:
> Yes. For example
>
> replace fullname = substr(fullname, 1, length(fullname) - 2) if
> substr(fullname, -2, 1) == " "
>
> Nick
>
> On Thu, Feb 28, 2013 at 6:41 AM, Dudekula, Anwar <[email protected]> wrote:
>
>> Is it possible to trim last word if it is one alphabet wide like removing. A from ( Graham , Tony A )
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/