How to compare strings
    17 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Daan Decleer
 il 29 Apr 2017
  
    
    
    
    
    Risposto: Walter Roberson
      
      
 il 29 Apr 2017
            Hello
I think my questions is fairly simple, but I just can't find the answer. I got an text DropDownBox in my app designer with the options: 'Mean', 'Clear' or 'Clear/Cloudy'. I declare a string SkyType as app.SkyTypeDropDown.Value, which gives me the String in the DropDown box. If The string SkyType = 'Mean', then a number SkyTypeNumber should become 1. If the string SkyType = 'Clear', SkyTypeNumber should become 2. And you guess yourself what SkyTypeNumber is when SkyType equals 'Clear/Cloudy'.
The problem is I really don't know how to compare SkyType (which is a string, with the '' included) and 'Mean', 'Clear' or 'Cloudy/Clear'.
I hope somebody can help me, and look out to your answers!
0 Commenti
Risposta accettata
  Walter Roberson
      
      
 il 29 Apr 2017
        strcmp() to compare character vectors
The "==" operator can be used to compare a String to a String, or a String to a character vector.
if strcmp(SkyType, 'Mean')
if SkyType == "Mean"                %R2017a or later to use "" strings in source code
if SkyType == string('Mean')        %R2016b or later
0 Commenti
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Characters and Strings in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

