convert char array to string
21 次查看(过去 30 天)
显示 更早的评论
between 2019b ans 2021b, function "fileparts" returned String instead of char, this caused many change in my code. iIs there away to obtain the legacy behavior in 2021b ?
thank
0 个评论
采纳的回答
Cris LaPierre
2022-6-20
编辑:Cris LaPierre
2022-6-20
The function fileparts creates output with the same data type as the input.
% String input = string output
fileS = "H:/user4/matlab/myfile.txt";
[filepath,name,ext] = fileparts(fileS)
% Char array input = char array output
fileC = 'H:/user4/matlab/myfile.txt';
[filepath,name,ext] = fileparts(fileC)
Check what you are using for input. You could use the convertStringsToChars function to convert your input to fileparts to char if necessary.
[filepath,name,ext] = fileparts(convertStringsToChars(fileS))
Or simply char(string), as Fangjun showed
[filepath,name,ext] = fileparts(char(fileS))
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!