필터 지우기
필터 지우기

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
Dominique Joubert
Dominique Joubert 2018년 8월 22일
i want a user to enter the right side of an equation:for example s+2*a-3/r
Stephen23
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
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개)

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

태그

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by