Effacer les filtres
Effacer les filtres

Comparing strings, case insensitive, without str functions

2 vues (au cours des 30 derniers jours)
Janell Lopez
Janell Lopez le 19 Avr 2016
Commenté : Janell Lopez le 21 Avr 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?

Réponse acceptée

James Tursa
James Tursa le 19 Avr 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.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by