Problem 44. Trimming Spaces
Given a string, remove all leading and trailing spaces (where space is defined as ASCII 32).
Input a = ' singular value decomposition ' Output b is 'singular value decomposition'
Solution Stats
Problem Comments
-
4 Comments
Show
1 older comment
Franck Dernoncourt
on 28 Jan 2012
Test #5 seems false:
I guess "a = sprintf('\ttab in front, space at end ');" should be a = '\ttab in front, space at end '.
Besides, tab is ASCII 9 (not 32).
Selvaraaju Murugesan
on 15 Jan 2013
@Franck..use isspace function. There is a difference between whitespace and tab space! BTW strtrim removes both white and tab space !
Sanzhar Askaruly
on 3 Jul 2019
pretty easy
Rik
on 13 Jan 2021
This problem should probably contain a test with only spaces as well. That requires solutions to be much more robust.
Solution Comments
Show commentsProblem Recent Solvers2409
Suggested Problems
-
Get the area codes from a list of phone numbers
1053 Solvers
-
605 Solvers
-
14719 Solvers
-
Find the dimensions of a matrix
521 Solvers
-
10502 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!