String 忽略\n(换行符)

String 忽略\n(换行符),string,matlab,newline,String,Matlab,Newline,我得到一个字符串,其中包含一个分为两行的句子: 'hello this is my first. program matlab' 我想把这句话改成在线表达: 'hello this is my first.program matlab' 如何使用matlab进行此操作?将所有出现的\n替换为' 例如,键入: strrep( sprintf('this is my \n string'),sprintf('\n'),'') 如果您只想删除字符串末尾的(可能的)新行,而保留所有其他行,该

我得到一个字符串,其中包含一个分为两行的句子:

'hello this is my first.
program matlab'
我想把这句话改成在线表达:

'hello this is my first.program matlab'

如何使用matlab进行此操作?

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

例如,键入:

   strrep( sprintf('this is my \n string'),sprintf('\n'),'')

如果您只想删除字符串末尾的(可能的)新行,而保留所有其他行,该怎么办?
   strrep( sprintf('this is my \n string'),sprintf('\n'),'')