Azzera filtri
Azzera filtri

Insertion of character in between others in a string

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

Pavel Gorodetsky
Pavel Gorodetsky il 15 Giu 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 Commento
Ole Hansen
Ole Hansen il 16 Giu 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?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by