Comparing accented strings from .fig files

Using strcmpi to compare combo box accented strings from a .fig (GUIDE) file fails. Checking these accented strings, I see each accented letter occupies 2 bytes. Is there another API that can successfully perform this string comparison with another string passed as a literal between '' ?

Respuestas (1)

Jan
Jan el 16 de Oct. de 2013
Editada: Jan el 16 de Oct. de 2013

1 voto

This is not clear yet. What is a "combo box" and does this detail matter at all? What is an "accented string"? A small example would reveal this important detail.
Not only "accented letters" occupy 2 bytes, but all characters have this property. The underlying type of char is UINT16, such that they can carry UTF16 strings. STRCMP can successfully handle them, so please explain the details of your problem.
What does "with another string passed as a literal between" mean?

5 comentarios

Luc Le Blanc
Luc Le Blanc el 16 de Oct. de 2013
Combo box: drop-down list linked to a downward-pointing arrow on its right.
Accented string: string containing accented characters, like 'Régression'
choices = get(handles.cboSelectionModele,'String')
strcmpi(choices(1), 'Régression')
In the line above, 'Régression' is passed as a literal between '' to be compared with the first string of the SelectionModele combo box. But it will always fail because the length of choices(1) is one character more than 'Régression'. GUIDE seems to encode its strings in a different way than my code. Of course this succeeds if the GUIDE string has no accented letter.
Jan
Jan el 16 de Oct. de 2013
Editada: Jan el 16 de Oct. de 2013
No, GUIDE does not do any magic string encoding. GUIDE create a FIG and an M-file only, so the result is pure Matlab code.
I assume, you do not mean "choices(1)", which is a cell, but "choices{1}".
What does this show:
double('Régression')
double(choices{1})
Luc Le Blanc
Luc Le Blanc el 17 de Oct. de 2013
Interesting: with double() I see there is a '\n' at the beginning of the first string and I notice other lists have that too. Is this customary in lists? I'm pretty new to MATLab, I'm debugging an existing app.
Jan
Jan el 17 de Oct. de 2013
@Luc: No, if there is a \n, you must have inserted it there. What exactly do you mean by "list"? This could be a cell string or a char-string with line breaks, a struct vector, ... ?
Luc Le Blanc
Luc Le Blanc el 17 de Oct. de 2013
I meant lists of strings in those drop-down lists. I just checked some 60 dialogs (.fig) and indeed, this '\n' prefix was the exception. Comparison works now. Phew!

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 16 de Oct. de 2013

Comentada:

el 17 de Oct. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by