I need to know if a string is at least one character or more. I need to find the uppercase
character .
I used this code:
str testStr;
int flag;
testStr = "abdE2" ;
flag = strScan(testStr , "ABCDEFGHILMNOPQRSTUVZ" ,flag ,strLen(testStr));
info(strFmt("%1",flag) );
But not work!
A problem is that the function strScan does not distinguish uppercase and lowercase.
There is a solution?
Thanks,
Enjoy!
Here is a job I wrote that shows 3 different methods of comparing strings with case sensitivity. Just copy/paste/run.
static void Job86(Args _args)
{
str a = 'Alex';
str b = 'aleX';
int i;
int n;
str c1, c2;
setPrefix("Compare");
for (n=1; n<=strLen(b); n++)
{
c1 = subStr(a, n, 1);
c2 = subStr(b, n, 1);
if (char2num(c1, 1) == char2num(c2, 1))
info(strFmt("Char2Num()\t%1 == %2", c1, c2));
else
info(strFmt("Char2Num()\t%1 != %2", c1, c2));
if (strCmp(c1, c2) == 0)
info(strfmt("strCmp()\t%1 == %2", c1, c2));
else
info(strFmt("strCmp()\t%1 != %2", c1, c2));
i = System.String::Compare(c1, c2);
if (i == 0)
info(strfmt("System.String::Compare()\t%1 == %2", c1, c2));
else
info(strFmt("System.String::Compare()\t%1 != %2", c1, c2));
}
}
The code below tests if a string is one character or more and afterwards finds all the uppercase characters. Numbers are ignored since they cannot be uppercase.
static void findCapitalLetters(Args _args)
{
str testStr = "!#dE2";
int i;
int stringLenght = strLen(testStr);
str character;
//Find out if a string is at least one character or more
if (stringLenght >= 1)
{
info(strFmt("The string is longer than one character: %1",stringLenght));
}
//Find the uppercase character (s)
for (i=1; i<=stringLenght; i+=1)
{
character = subStr(testStr, i, 1);
if (char2num(testStr, i) != char2num(strLwr(testStr), i))
{
info(strFmt("'%1' at position %2 is an uppercase letter.", character, i));
}
}
}
This is the output:
EDIT: Like Jan B. Kjeldsen pointed out, use char2num(testStr, i) != char2num(strLwr(testStr), i)
and not char2num(testStr, i) == char2num(strUpr(testStr), i)
to make sure it evaluates symbols and numbers correctly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.