Filter löschen
Filter löschen

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

21 Ansichten (letzte 30 Tage)
H.O
H.O am 14 Feb. 2024
Kommentiert: Dyuman Joshi am 15 Feb. 2024
文字列(string)のうしろから3文字(空白を含む)を削除したいです.
どのようにすると良いでしょうか?
例)
A=
"aaa 01"
"bbb 02"
"aaa 02"
"bbb 03"
"ccc 04"
...
削除→ 
A=
"aaa"
"bbb"
"aaa"
"bbb"
"ccc"
...

Akzeptierte Antwort

Dyuman Joshi
Dyuman Joshi am 14 Feb. 2024
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 Kommentare
H.O
H.O am 15 Feb. 2024
Thank you so much.
Dyuman Joshi
Dyuman Joshi am 15 Feb. 2024
You're welcome!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 文字と文字列 finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!