String Copying without Spaces

12 views (last 30 days)
Ash
Ash on 14 May 2012
i have a string a= [a b c d] separated by two spaces n i want to copy it in another string like b=[abcd] by removing the spaces. Please help.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 14 May 2012
a = 'a b c d'
b = regexprep(a,' ','')
or
b = setdiff(a,' ')
or
b = f(~ismember(a,' '))
or
b = strrep(a,' ','')
  2 Comments
Ash
Ash on 14 May 2012
Thanks alot for ur help...It worked..
Jan
Jan on 14 May 2012
Or:
b = a(~isspace(a));
b = a(a ~= ' ');
b = a; b(strfind(b, ' ')) = [];
I assume, that the STRREP method is the fastest.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!