Limit length of a string
    20 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Christian Günther
      
 el 16 de En. de 2023
  
    
    
    
    
    Respondida: Christian Günther
      
 el 16 de En. de 2023
            Hello,
How can I limit the lengt of strings that I print out ?
text1 contains a sting of length 7 to 25, but I want to print a maximum of 18 charactes.
I have tried the following, but it does not work for text1:
text1='012345678901234567890123456789';
text2='01234567';
sprintf('%-18s',text1)
sprintf('%-18s',text2)
In the end it should look like a table.
Best regards
Christian
0 comentarios
Respuesta aceptada
Más respuestas (2)
  Matt J
      
      
 el 16 de En. de 2023
        text1='012345678901234567890123456789';
text2='01234567';
text1(19:end)=''
text2(19:end)=''
  Walter Roberson
      
      
 el 16 de En. de 2023
        https://www.mathworks.com/help/matlab/ref/extractbefore.html
This can be used in an expression without modifying the variable. Also it can be used with string() objects as well
1 comentario
Ver también
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!


