How can I add a character in between two characters in specific order in a string?
조회 수: 5 (최근 30일)
이전 댓글 표시
I have a list of elements as strings. For example,
6Li2 17O2 17O C+D3 C+D3 C3 28Si+H3 13C+D3 23Na C2+H4 13C2+H2
Every time there's a number after a letter I want to add a multiplication sign. So H3 would be H*3 but 13C would remain 13C. I was thinking of using if,else statements and use isstrprop to find if it is letter then digit but not sure how to do this. Is there a better way?
댓글 수: 0
답변 (1개)
Tiasa Ghosh
2018년 8월 30일
편집: Tiasa Ghosh
2018년 8월 30일
Maybe you could use iteration for all element of string array. First find the position pos of the number in the string with strfind. Then check if the element in pos-1 is a letter character with ~isnan. If yes, insert a * with sprintf
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!