How do I make a file name with combination of two strings ?

26 vues (au cours des 30 derniers jours)
farzad
farzad le 10 Jan 2018
Réponse apportée : Jan le 10 Fév 2018
Hi All
How do I make a file name with combination of two strings ? most of the examples I have seen are combination of a file and a number

Réponse acceptée

Jan
Jan le 10 Fév 2018
folder = 'D:\Temp';
str1 = 'aaa'
str2 = 'bbb'
% Alternatives:
name = [str1, str2]
name = strcat(str1, str2)
name = cat(2, str1, str2)
name = horzcat(str1, str2)
name = sprintf('%s%s', str1, str2) % See Stephen's solution
% Creates: C\Temp\aaa\bbb
fullname = fullfile(folder, str1, str2)

Plus de réponses (1)

Stephen23
Stephen23 le 4 Fév 2018
Modifié(e) : Jan le 10 Fév 2018
Use sprintf and adjust the format string to suit:
S1 = 'hello';
S2 = 'world';
name = sprintf('%s%s.txt',S1,S2)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by