Comparing strings, case insensitive, without str functions

5 visualizaciones (últimos 30 días)
Janell Lopez
Janell Lopez el 19 de Abr. de 2016
Comentada: Janell Lopez el 21 de Abr. de 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?

Respuesta aceptada

James Tursa
James Tursa el 19 de Abr. de 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.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by