필터 지우기
필터 지우기

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 CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by