How can I find the index of a the characters within a string?
76 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Akira Agata
on 8 Feb 2018
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 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!