忽略\n(换行符)

4
我收到了一个包含两行句子的字符串:

我收到了一个包含两行句子的字符串:

'hello this is my first.
program matlab'

我希望您能将这句话改为一行:

'hello this is my first.program matlab'

我该如何使用Matlab实现这个功能?
1个回答

8

将所有出现的\n替换为''

   myNewSt = strrep(mySt,sprintf('\n'),'');

例如,输入:
   strrep( sprintf('this is my \n string'),sprintf('\n'),'')

如果你只想删除字符串末尾的(可能的)换行符,并保留其他所有的换行符,该怎么办? - Antonio Sesto

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接