Merge parts that make up the string

2 views (last 30 days)
Alberto Acri
Alberto Acri on 27 Nov 2022
Answered: dpb on 27 Nov 2022
Hello! I have a 1x5 string.
I would like to merge all the 5 parts that make up the string so that I have one overall string.
Between each string there must be a "_" symbol.
I have tried it this way
string_final = strcat(strPieces(1),"_", strPieces(2),"_", strPieces(3),"_", strPieces(4),"_", strPieces(5));
but I want to get the same result with something more generic and that can be directly referenced to the value 5 (as it might change).
For example:
number_of_string = 5;
string_final = strcat(strPieces(1:number_of_string), "_");

Accepted Answer

dpb
dpb on 27 Nov 2022
S=string(['A':'E'].'); % an arbitrary array of strings
join(S,"_") % join with underscore character
ans = "A_B_C_D_E"

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!