inputdlg - how do i recognise if someone entered a symbol, e.g. = into the box?
2 ビュー (過去 30 日間)
古いコメントを表示
how do i recognise if someone entered a symbol, e.g. = into the box?
4 件のコメント
Stephen23
2018 年 8 月 22 日
編集済み: Stephen23
2018 年 8 月 22 日
What about all of the ASCII control characters, i.e. char(0:31)? What about non-breaking spaces, en dashes, em dashes, etc?
There are many characters that you are likely to want to exclude, and building a list of them all is intractable. It would be much easier to define what characters are allowed, as this list will be much smaller. For that you can use a regular expression.
Note that writing a language parser is not a trivial task.
採用された回答
Niklas Nylén
2018 年 8 月 22 日
Verifying that the expression is a valid equation is probably extremely hard, but validating that only "allowed" symbols are entered is quite simple using regexp:
% Allowing +, -, *, / and space. Expand list if needed.
validSpecialChars = regexptranslate('escape', '+-*/ ')
assert(isempty(regexp(input, ['[^A-Za-z0-9' validSpecialChars ']'], ...
'Expression %s contains invalid characters', input)
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Argument Definitions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!