Insertion of character in between others in a string

5 Ansichten (letzte 30 Tage)
Ole Hansen
Ole Hansen am 15 Jun. 2012
Say I have a cell array:
cell_array={'AA','KK','AKs','QQ','AKo'}:
How do I attach the different suits (i.e. heart, club, spade, and diamond) into the string? (I would like to expand the given combinations with their respective suits).
Example:
for pair AA: AhAc, AhAs, AhAd, AcAs, AcAd, AsAd
and for suited nonpair AKs: AhKh, AcKc, AsKs, AdKd
and so forth for the remaining pairs, suited nonpairs and offsuit nonpairs.
It seems that 'str', 'strrep', etc. can only append a character in the end of a string - I would like to insert a character (h,c,s,d) in between as shown above.

Akzeptierte Antwort

Pavel Gorodetsky
Pavel Gorodetsky am 15 Jun. 2012
well, appending a single character to another string is simple: str1 = ['AA', 's']
to insert characters in the middle of the string, i would first concatenate the strings and then change the order of the characters. for example:
str1 = ['AA' , 'hc'];
str1 = str1([1, 3, 2, 4])
  1 Kommentar
Ole Hansen
Ole Hansen am 16 Jun. 2012
Thank you very much!
Say I get a resulting array:
cell_array={'AX','BY'};
It is easy to manipulate the strings 'AX' and 'BY' (to isolate, sort, identify etc.), but I cannot seem to find an approach to "look" into the individual components of 'AX' or 'BY'. I would like to make a loop in which I only consider 'AX' and not 'BY'. Specifically, I would like to consider the case with 'A' (and not 'AX' while keeping 'AX' intact for subsequent analyses, i.e. not remove the 'X')
Should I maybe post a new thread?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by