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!