Problem 44. Trimming Spaces
Solution Stats
Problem Comments
-
4条评论
测试#5似乎是错误的:
我猜“ a = sprintf('\ ttab在前面,末端空间');”应该是前面的a ='\ ttab,末端空间'。
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 !
相当容易
This problem should probably contain a test with only spaces as well. That requires solutions to be much more robust.
Solution Comments
-
1 Comment
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.
-
1 Comment
中间没有多个空间的测试用例。我曾考虑过strjoin(strsplit),如果您从strsplit操作中删除了空单元,它将通过此处的所有测试,但是它会将中间的多个空间减少到一个。
-
1 Comment
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.
-
1 Comment
如果您有MATLAB> = 2016b
-
1 Comment
i do not understand what the solution of test 5 should be, or why my solution is wrong
-
1 Comment
One line
-
1 Comment
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.
-
1 Comment
Test case 5 is failing for strtrim(str) or isspace(str) functions - both consider \t as space.
-
2 Comments
-
1 Comment
How is this able to pass test 5? It should remove the leading tab and fail.
-
1 Comment
check the test 5????
Problem Recent Solvers1806
Suggested Problems
275个求解器
Replace multiples of 5 with NaN
386个求解器
Create an n-by-n null matrix and fill with ones certain positions
441个求解器
解决328
507 Solvers
来自作者的更多95
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
开始狩猎!