フィルターのクリア

How to remove additional comma from string?

10 ビュー (過去 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 Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by