How can I find the index of a the characters within a string?
74 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Akira Agata
el 8 de Feb. de 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 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!