Effacer les filtres
Effacer les filtres

Insertion of character in between others in a string

1 vue (au cours des 30 derniers jours)
Ole Hansen
Ole Hansen le 15 Juin 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.

Réponse acceptée

Pavel Gorodetsky
Pavel Gorodetsky le 15 Juin 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 commentaire
Ole Hansen
Ole Hansen le 16 Juin 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?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by