Why does strtok cut too much out of my string?
6 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Thorsten
2015 年 10 月 28 日
編集済み: Thorsten
2015 年 10 月 28 日
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_', '');
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!