How can I find the index of a the characters within a string?

74 vues (au cours des 30 derniers jours)
Diane Ha
Diane Ha le 7 Fév 2018
Modifié(e) : per isakson le 8 Fév 2018
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,' ');

Réponses (1)

Akira Agata
Akira Agata le 8 Fév 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

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by