inputdlg - how do i recognise if someone entered a symbol, e.g. = into the box?

1 Ansicht (letzte 30 Tage)
how do i recognise if someone entered a symbol, e.g. = into the box?
  4 Kommentare
Dominique Joubert
Dominique Joubert am 22 Aug. 2018
i want a user to enter the right side of an equation:for example s+2*a-3/r
Stephen23
Stephen23 am 22 Aug. 2018
Bearbeitet: Stephen23 am 22 Aug. 2018
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Niklas Nylén
Niklas Nylén am 22 Aug. 2018
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)

Weitere Antworten (0)

Kategorien

Mehr zu Argument Definitions finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by