Getting parts of string with for loop

4 visualizaciones (últimos 30 días)
Benedikt Skurk
Benedikt Skurk el 5 de Mzo. de 2021
Respondida: Prudhvi Peddagoni el 8 de Mzo. de 2021
Hi hopefully u can help me!
I have the attached string (picture) and now i want to get from every string in every column the word between the last \ and dot. So for example for the first column i would like to get Gös-Schb2_Ma142-Schb.
The problem is that i will have files later with a different pattern. So its important that i can find with the code the last backslash and dot. My code is:
pointLocation = strfind(A, '.');
underlineLocation = strfind(A, '\');
firstPart = A(underlineLocation(end):pointLocation(end));
But its not working at all...maybe u can help me?
  4 comentarios
Stephen23
Stephen23 el 5 de Mzo. de 2021
Editada: Stephen23 el 5 de Mzo. de 2021
"That is just for filenames i guess..."
The function has no idea if the input text is a filename of not. It just identifies the relevant separator characters.
"...and to seperate filename and path"
and file extension.
"But i have strings in a table right?"
That is the very first time you used the term table. Your screenshot shows a 1x408 string array, not a table.
"Dont know how i can work with that."
You could try using fileparts. The loop probably isn't required either.
Mathieu NOE
Mathieu NOE el 5 de Mzo. de 2021
hello
so what does your code generate ?
is it possible for you to send a few examples of strings ?

Iniciar sesión para comentar.

Respuesta aceptada

Prudhvi Peddagoni
Prudhvi Peddagoni el 8 de Mzo. de 2021
Hi,
As Stephen Cobeldick pointed out. fileparts function does exactly what you are looking for. the second output, name, is the part of the string that is after last '/' and before last '.'. So you can get the strings from a table and give it to this function.
Hope this helps.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by