string choppping
古いコメントを表示
Is there a way to chop off part f a sting after a certain set of characters?
If I use strtok( ) It seems to only look at the first character in the deliminter. Is there a way to make the command look at a certain string as a delimiter rather than a char?
Thanks
採用された回答
その他の回答 (6 件)
Walter Roberson
2011 年 6 月 17 日
1 投票
As you are chopping, you could use strfind to get the index (watch out for multiple occurrences) and then use straight indexing.
Fangjun Jiang
2011 年 6 月 17 日
help strrep
help regexp
help regexprep
If you provide an example, many expert would be eager to try their regular expression skills.
Andrew Newell
2011 年 6 月 17 日
token = strtok(str, delimiter)
2 件のコメント
Walter Roberson
2011 年 6 月 17 日
Nope. "If the delimiter input specifies more than one character, MATLAB treats each character as a separate delimiter; it does not treat the multiple characters as a delimiting string"
Andrew Newell
2011 年 6 月 17 日
How dare MATLAB conflict with my personal reality? However, the source code for STRTOK would make a good starting point for creating a function that handles longer delimiters.
William
2011 年 6 月 20 日
0 投票
1 件のコメント
Fangjun Jiang
2011 年 6 月 20 日
You shall explain what is your need for the "chopping". Giving a path string and get the lowest folder name? If that is the case, fileparts() would be the best. This outloc is just an example, right? There are many ways to do it. For example:
regexprep(outloc,'.+\\','')
Gerd
2011 年 6 月 20 日
Hi William,
if you use
str = outloc(strfind(outloc,'\MATLAB'):end)
you will get
str = \MATLAB
Gerd
William
2011 年 6 月 21 日
0 投票
1 件のコメント
Fangjun Jiang
2011 年 6 月 21 日
Bill, would newstring=regexprep(stringinput,[pat,'.*'],'') work for your task?
カテゴリ
ヘルプ センター および File Exchange で String Parsing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!