文字列から指定数だけ削除

60 ビュー (過去 30 日間)
H.O
H.O 2024 年 2 月 14 日
コメント済み: Dyuman Joshi 2024 年 2 月 15 日
文字列(string)のうしろから3文字(空白を含む)を削除したいです.
どのようにすると良いでしょうか?
例)
A=
"aaa 01"
"bbb 02"
"aaa 02"
"bbb 03"
"ccc 04"
...
削除→ 
A=
"aaa"
"bbb"
"aaa"
"bbb"
"ccc"
...

採用された回答

Dyuman Joshi
Dyuman Joshi 2024 年 2 月 14 日
A = ["aaa 01"
"bbb 02"
"aaa 02"
"bbb 03"
"ccc 04"]
A = 5x1 string array
"aaa 01" "bbb 02" "aaa 02" "bbb 03" "ccc 04"
%Number of characters from end to delete
n = 3;
B = extractBefore(A, strlength(A) - n +1)
B = 5x1 string array
"aaa" "bbb" "aaa" "bbb" "ccc"
  2 件のコメント
H.O
H.O 2024 年 2 月 15 日
Thank you so much.
Dyuman Joshi
Dyuman Joshi 2024 年 2 月 15 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!