Anyone know the error checking for special characters

Hello there, I've been at this for a while now but i just can't seem to to find the error check for special characters like, * @!. Please help

2 件のコメント

Adam
Adam 2015 年 4 月 27 日
in what context?
Vivie
Vivie 2015 年 4 月 27 日
i'm writing a simple program that asks the user to enter variables but i'd like to error check it so it's not easily crushed. I've used error checks like isinf, is numeric, isreal. I would like to send the program into a loop should the user use special characters. Does that help.

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

回答 (1 件)

Udit Gupta
Udit Gupta 2015 年 4 月 27 日

0 投票

You can use regular expressions. The code will go something like this -
if any(regexp(str,'[^_a-zA-Z0-9]+'))
<error condition>
end
You will need to use a more sophisticated regEx format if you need more robust checking. Like:
if any(regexp(str,'^[a-zA-Z_][a-zA-Z0-9_]*$'))
<valid>
else
<invalid>
end

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

質問済み:

2015 年 4 月 27 日

回答済み:

2015 年 4 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by