strjoin, string, remove a single space, while combining variables.

조회 수: 5 (최근 30일)
Tyler Young
Tyler Young 2020년 2월 22일
댓글: Walter Roberson 2020년 2월 23일
I have to do this in this manner for a hw question, I know there are other ways to acomplish the same thing....
X = strjoin([ "The" , "cat" ], " ")
Y = strjoin([ "over" , "the" , "fence" ], " ")
Z = strjoin([ X ,"jumped", Y ,"." ], " ")
"Z" has a space between the end of string "Y" and the added period, I need to remove just that space while maintaining the rest of the spaces between the other strings.
How do I get.....
"The cat jumped over the fence." % no space between "fence" and "."

채택된 답변

Walter Roberson
Walter Roberson 2020년 2월 22일
Join one fewer item in Y, and strcat() or + it on to the end.
If you absolutely must use only strjoin, then join one fewer item into Y, and strjoin the result with "" (empty string) using "." as the joining character.
  댓글 수: 2
Tyler Young
Tyler Young 2020년 2월 23일
Thank you for response, I must use strjoin, but I'm not sure what you mean by "" (empty string) using "." as joining character

댓글을 달려면 로그인하십시오.

추가 답변 (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