问题
This is a follow-up question from this that considered evalc
, instead of figgling with file-descriptors manually. You can see below an example about poor sanitization. I want to remove things such as trailing characters, all whitespaces, all newlines etc -- that usually cause unexpected things -- is there a ready sanitization command to do this?
EDU>> a
a =
1 +1*{x} -1*{y}*{z}
EDU>> b
b =
1 +1*{x} -1*{y}*{z}
EDU>> isequal(a,b)
ans =
0
回答1:
I don't know whether there exist any ready robust implementation but this works pretty well
xx=@(x)regexprep(x,'\s',''); isequal(xx(a),xx(b))
where I use anonymous function and remove some oddities such as trailing whitespaces/newlines often hard to see on the window.
Also, the commands such as strtrim()
and deblank()
can be useful to you in removing trailing characters.
来源:https://stackoverflow.com/questions/15991945/sanitize-string-for-comparison-in-matlab