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

文字列(string)のうしろから3文字(空白を含む)を削除したいです.
どのようにすると良いでしょうか?
例)
A=
"aaa 01"
"bbb 02"
"aaa 02"
"bbb 03"
"ccc 04"
...
削除→ 
A=
"aaa"
"bbb"
"aaa"
"bbb"
"ccc"
...

 Respuesta aceptada

Dyuman Joshi
Dyuman Joshi el 14 de Feb. de 2024

0 votos

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 comentarios

H.O
H.O el 15 de Feb. de 2024
Thank you so much.
Dyuman Joshi
Dyuman Joshi el 15 de Feb. de 2024
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2022b

Etiquetas

Preguntada:

H.O
el 14 de Feb. de 2024

Comentada:

el 15 de Feb. de 2024

Community Treasure Hunt

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

Start Hunting!