フィルターのクリア

How to recognize it is uppercase ,lowercase , or other sign ?

82 ビュー (過去 30 日間)
MD Anower Hossain
MD Anower Hossain 2019 年 10 月 4 日
コメント済み: Mahmoud Elbeltagy 2020 年 8 月 10 日
what's wrong here ? why it does'nt work properly ???
prompt = "Pls Enter a character"
ease enter an latter: ";
a = input(prompt,"s");
if (a>="65" || a<="90")
fprintf("this is UPPERCASE \n ");
elseif (a>="97" || a<="122")
fprintf("leading character \n");
else
fprintf("It is %s\n",a);
end

採用された回答

Stephen23
Stephen23 2019 年 10 月 4 日
編集済み: Stephen23 2019 年 10 月 4 日
Your logic is incorrect, you should be using &&, not ||
Also you are comparing against strings of the character values, whereas you should either compare against the characters themselves or against the character numeric values. It makes no sense to compare against strings of the character values.
So you should be doing either one of these:
a>=65 && a<=90
a>='A' && a<='Z'
By the way, here is a much simpler vectorized method to detect upper/lower case letters:
>> v = 'aBCde$';
>> isup = lower(v)~=v
isup =
0 1 1 0 0 0
>> islo = upper(v)~=v
islo =
1 0 0 1 1 0
Another simple option is to call isstrprop:
>> isstrprop(v,'upper')
ans =
0 1 1 0 0 0
>> isstrprop(v,'lower')
ans =
1 0 0 1 1 0
  1 件のコメント
Mahmoud Elbeltagy
Mahmoud Elbeltagy 2020 年 8 月 10 日
nice way of thinking, i really liked the second way :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by