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

14 次查看(过去 30 天)
H.O
H.O 2024-2-14
文字列(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 个)

类别

Help CenterFile Exchange 中查找有关 文字と文字列 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!