I’m wanting to check whether a character is upper case vs anything else. I wrote something that I’m ‘sure’ I’ve used in the past and even ‘surer’ that it worked as desired. Now it doesn’t; so I need a replacement. This is the whole chunk
of code. I expecting that if a=’m’, the if statement will fail; but if a=’M’, the test is true and groupauthor is 0.
string a(a1). compute #i=char.length(author). compute a=char.substr(author,#i,1). compute groupauthor=1. if (a ge 'A' and a le 'Z') groupauthor=0. format groupauthor(f1.0). execute. Thanks, Gene Maguin |
If you know that the last character is alphabetic (not a number, blank, punctuation etc), you can just do this for a variable named s. compute isupper = char.substr(s, char.length(s),1) eq upcase(char.substr(s,char.length(s),1)). If you want a bulletproof method that handles anything, you can do this. spssinc trans result = isupper type=4 /formula "unicodedata.category(s[-1].rstrip())". If it is an uppercase character, the result will be "Lu" (Unicode upper case letter). The problem with the code above might be that you are not in Unicode mode, so trailing blanks are not stripped but you were before. On Tue, Mar 31, 2020 at 7:01 AM Maguin, Eugene <[hidden email]> wrote:
|
I can’t guarantee that the last character is only alpha. There definitely are periods and a left paren. As to Unicode. I looked at the edit ->options and Character encoding is set to Unicode and not to local system.
Re: your ps. One does have an accent character but it may be the only one and I can find that because it ‘should’ give a zero in the test. From: Jon Peck [mailto:[hidden email]]
If you know that the last character is alphabetic (not a number, blank, punctuation etc), you can just do this for a variable named s. compute isupper = char.substr(s, char.length(s),1) eq upcase(char.substr(s,char.length(s),1)). If you want a bulletproof method that handles anything, you can do this. spssinc trans result = isupper type=4 If it is an uppercase character, the result will be "Lu" (Unicode upper case letter). The problem with the code above might be that you are not in Unicode mode, so trailing blanks are not stripped but you were before. On Tue, Mar 31, 2020 at 7:01 AM Maguin, Eugene <[hidden email]> wrote:
-- Jon K Peck |
Free forum by Nabble | Edit this page |