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'
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).
@Franck..use isspace function. There is a difference between whitespace and tab space! BTW strtrim removes both white and tab space !
Isn't the use of regexp or regexprep supposed to be limited? It's not that I dislike using it, it's just that these string problems seem to be becoming a regexprep practice.
There's no test case with multiple spaces in the middle. I had considered strjoin(strsplit), which would pass all the tests here if you removed empty cells from the strsplit operation, but it would reduce multiple spaces in the middle to one.
I am sure that there is a more efficient way to perform this operation with just regexp, but the intricacies of this wonderful function still elude me.
works if you have MATLAB >= 2016b
i do not understand what the solution of test 5 should be, or why my solution is wrong
Keeps failing test 5 because pretty much all Matlab functions treat \t as space. Tried strtrim(a), isspace(a(i)) = 1, textscan(a,'%s').
The only thing that picks it up is isequal(a(1),' ') = 0. So, only brute force loop can pass test 5.
Not worth the effort.
Test case 5 is failing for strtrim(str) or isspace(str) functions - both consider \t as space.
Would fail for double spaces within string
Check out the "anchor" expressions $ and ^.
How is this able to pass test 5? It should remove the leading tab and fail.
check the test 5????
Back to basics 4 - Search Path
Back to basics 5 - Clipboard
Multiply a column by a row
Determine the number of odd integers in a vector
Dimensions of a rectangle
Find the palindrome
Get the area codes from a list of phone numbers
Find the sum of all the numbers of the input vector
Find the two most distant points
Reverse Run-Length Encoder
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office