Why does strtok cut too much out of my string?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I am using the strtok function to cut out a certain part of my strings. I have a lot of filenames with the exact string in the beginning of the name and would like to get out the last part of the string.
Eg: Filenmes{1,1} = 'ID_setup_CMJ_L_2' Filenmes{2,1} = 'ID_setup_DJ_R_1'
So I want to get something like:
Names{1,1} = 'CMJ_L_2' Names{2,1} = 'DJ_R_1'
I use the following line for this:
[prt1, prt2] = strtok(filenmes{i,1},'ID_setup_')
It works fine for all of my filenames except for the DJ's.. then it gives me Names({2,1} = 'J_R_1' (instead of DJ_R_1).
Thus, it cuts out that 'D' which it does not do in all of my other examples (CMJ,NonCMJ,HH,...)
Any suggestions? Are there perhaps better ways to do this?
Thanks!
0 commentaires
Réponse acceptée
Thorsten
le 28 Oct 2015
Modifié(e) : Thorsten
le 28 Oct 2015
This is because you specify a set of delimiters in the second argument of the strtok function, and 'D' is a delimiter. Leading delimiters are ignored, so the D in JD is cut.
Instead of strtok, you can may want to use strrep
newfilename = strrep(filenmes{i,1},'ID_setup_', '');
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!