How to remove additional comma from string?

조회 수: 13 (최근 30일)
Pete sherer
Pete sherer 2022년 8월 25일
이동: Rik 2022년 8월 26일
tdat = ["t1,t2,t3", "d2,d3,d4,"]'
How can I remove the extra comma delimiter from string above so result is
tdat = ["t1,t2,t3", "d2,d3,d4"]'
Thanks
  댓글 수: 1
Rik
Rik 2022년 8월 25일
What have you tried? There are general purpose functions that can do this, as well as string specific functions.

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

채택된 답변

Stephen23
Stephen23 2022년 8월 26일
tdat = ["t1,t2,t3"; "d2,d3,d4,"]
tdat = 2×1 string array
"t1,t2,t3" "d2,d3,d4,"
tdat = regexprep(tdat,',+$','')
tdat = 2×1 string array
"t1,t2,t3" "d2,d3,d4"
  댓글 수: 1
Pete sherer
Pete sherer 2022년 8월 26일
이동: Rik 2022년 8월 26일
Thanks very much for your suggestions

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

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 8월 25일
Try endsWith and extractBefore like this:
tdat = ["t1,t2,t3", "d2,d3,d4,"]'
tdat = 2×1 string array
"t1,t2,t3" "d2,d3,d4,"
for k = 1 : numel(tdat)
if endsWith(tdat(k), ',')
strLength = length(char(tdat(k)));
tdat(k) = extractBefore(tdat(k), strLength)
end
end
tdat = 2×1 string array
"t1,t2,t3" "d2,d3,d4"
tdat
tdat = 2×1 string array
"t1,t2,t3" "d2,d3,d4"

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by