フィルターのクリア

Insertion of character in between others in a string

1 回表示 (過去 30 日間)
Ole Hansen
Ole Hansen 2012 年 6 月 15 日
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.

採用された回答

Pavel Gorodetsky
Pavel Gorodetsky 2012 年 6 月 15 日
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 件のコメント
Ole Hansen
Ole Hansen 2012 年 6 月 16 日
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?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by