left characters of a string
    48 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Danielle Leblanc
 le 6 Juil 2011
  
    
    
    
    
    Réponse apportée : Steven Lord
    
      
 le 26 Nov 2022
            if I have a name 'Microsoft', how can i get the first 6 characters 'Micros'?
0 commentaires
Réponse acceptée
  Andrei Bobrov
      
      
 le 6 Juil 2011
        name = 'Microsoft'
out = name(1:6)
2 commentaires
  Stephen23
      
      
 le 26 Nov 2022
				name = 'Microsoft';
name(1:min(end,6))
name = 'Cat';
name(1:min(end,6))
Plus de réponses (1)
  Steven Lord
    
      
 le 26 Nov 2022
        This wasn't an option when the question was originally asked, but the extractBefore function will work for both char vectors and string arrays.
c = 'Microsoft'
c6 = extractBefore(c, 7)
s = string(c)
s6 = extractBefore(s, 7)
0 commentaires
Voir également
Catégories
				En savoir plus sur Characters and Strings 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!




