How can I find the index of a the characters within a string?
76 ビュー (過去 30 日間)
古いコメントを表示
Input_String = 'Hello World';
Num_Letters = numel(Input_String);
Index_Letters = % I used find(Input_String), but it gives me 1:11 as index, when I only need 1:11 without index 6. At index 6, it's a blankspace.%
Num_Blanks = sum(Input_String ==' ');
Index_Blanks = strfind(Input_String,' ');
0 件のコメント
回答 (1 件)
Akira Agata
2018 年 2 月 8 日
There are many useful functions to handle string data. Please refer to the related documentation page ( https://jp.mathworks.com/help/matlab/characters-and-strings.html ).
The followings are some example.
Input_String = 'Hello World';
- To find the index of the space (' ')
idx = strfind(Input_String,' ');
- To count the number of space character
num = count(Input_String,' ');
- To replace space with specific character
newString = replace(Input_String,' ','YourString');
- To erase space
newString = erase(Input_String,' ');
...etc
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!