Why isn't strtrim working on my string?
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
JFz
el 31 de Jul. de 2017
Comentada: JFz
el 31 de Jul. de 2017
Hi,
I have a simple string, that has many leading spaces: a = ' abcd' I want to remove the white space by using strtrim, but it is not working. I used ['|' a '|'] and then newchr = strtrim(a) but the newchr still has the leading spaces. Why?
The string a is read from excel file which I tried to remove the spaces but also failed.
Thanks,
Jennifer
1 comentario
Adam
el 31 de Jul. de 2017
What does this mean: 'I used ['|' a '|'] '?
strtrim(a)
works fine for me applied to the string you post.
Respuesta aceptada
the cyclist
el 31 de Jul. de 2017
Editada: the cyclist
el 31 de Jul. de 2017
For example, if you do
s = [char(160) 'abcd']
strtrim(s)
then the strtrim command will have no effect.
What do you get for these whitespace characters if you type
double(s)
where s is your string?
You could use regexprep to get rid of significant whitespace:
s = regexprep(s,char(160),'')
You'll need to take care of not removing those special characters from other places.
Más respuestas (0)
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!