如何将单引号放在字符串中?

Tim*_*len 0 matlab

我在MATLAB中遇到字符串问题,默认字符串是C:\Users\Root\Downloads\Path.我想在这里用单引号制作这个字符串'C:\Users\Root\Downloads\Path\'.我尝试多次使用反斜杠来逃避字符串,就像其他编程语言一样,但MATLAB没有这样做我不知道如何解决这个问题.

码:

clear all
clc
s='C:\Users\Root\Downloads\Path';
str=fprintf('%s',s);
Run Code Online (Sandbox Code Playgroud)

Ste*_*fin 5

诀窍是使用两个引号而不是一个:

s='''C:\Users\Root\Downloads\Path''';    
str=fprintf('%s',s)
'C:\Users\Root\Downloads\Path'
str =    
    30
Run Code Online (Sandbox Code Playgroud)

请注意,这str将是数字30,因为它fprintf返回它打印的字符数,而不是字符串本身!如果你只想要字符串,那么第一行就足够了.

disp(s)
'C:\Users\Root\Downloads\Path'
Run Code Online (Sandbox Code Playgroud)

请注意,MATLAB中没有数据类型"String".你有一个字符数组.