Comparing strings, case insensitive, without str functions
4 views (last 30 days)
Show older comments
Janell Lopez
on 19 Apr 2016
Commented: Janell Lopez
on 21 Apr 2016
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 Comments
Accepted Answer
James Tursa
on 19 Apr 2016
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.
More Answers (0)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!