1

我正在使用 textscan 读取文本文件,我得到 <55x1 cell> 示例:

 'aa a aa'
 'a  aaaa a'
 'a =  aaaaa'
 'aaaaaa'
 ' a a a aaa'
 'aa'
 'aaa'
 'aaaa'
  .
  . 
  .
  .

我想删除每个刺痛中的空格如果我有刺痛

 string = 'I am 24 Years    old'

我用

  string(ismember(string,' ')) = [];

它会消除空格,我会得到

 'Iam24Yearsold'

但是细胞不工作或者我不知道该怎么做我该怎么做?请问有什么建议吗?

4

1 回答 1

5

You can use strrep:

a = { 'aa a aa'
 'a  aaaa a'
 'a =  aaaaa'
 'aaaaaa'
 ' a a a aaa'
 'aa'
 'aaa'
 'aaaa'
 'I am 24 Years    old'};

strrep(a, ' ', '')

This results in

ans = 

    'aaaaa'
    'aaaaaa'
    'a=aaaaa'
    'aaaaaa'
    'aaaaaa'
    'aa'
    'aaa'
    'aaaa'
    'Iam24Yearsold'
于 2013-07-23T11:22:30.903 回答