Comparing strings, case insensitive, without str functions
5 次查看(过去 30 天)
显示 更早的评论
I have a project I'm working on for school where we write a Palindrome function. We are supposed to use the "programming method" and write it without using any built-in functions with "str", "eval","flip" or "printf". I have it such that the input word is flipped, and then I was going to compare the strings, but I can't for the life of me figure out what function to use that is not strcmpi to find whether or not the backwards string is equal to the forwards string. It must be case insensitive, so I can't use isequal. Any suggestions?
0 个评论
采纳的回答
James Tursa
2016-4-19
Do you know how to compare, in a case insensitive way, whether two characters are equal or not? Once you can do that, just put it in a loop to compare your string characters one-by-one. Hint: MATLAB uses the ASCII encoding for characters, so there is a pattern between the lower and upper case alphabet. E.g., consider this:
alphabet = char('a'+(0:25))
ALPHABET = char('A'+(0:25))
double(alphabet)
double(ALPHABET)
alphabet - ALPHABET
You can use the results of this code to come up with a scheme for comparing when two characters are the same in a case insensitive way.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!