How to remove additional comma from string?

14 visualizaciones (últimos 30 días)
Pete sherer
Pete sherer el 25 de Ag. de 2022
Movida: Rik el 26 de Ag. de 2022
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 comentario
Rik
Rik el 25 de Ag. de 2022
What have you tried? There are general purpose functions that can do this, as well as string specific functions.

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 26 de Ag. de 2022
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 comentario
Pete sherer
Pete sherer el 26 de Ag. de 2022
Movida: Rik el 26 de Ag. de 2022
Thanks very much for your suggestions

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 25 de Ag. de 2022
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"

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by