Replace a single character with a new line in a string
Mostrar comentarios más antiguos
Hello there,
I have a string for example: 'hello there how are you today'
All i want to do is to index a character, remove that indexed character and then create a new line.
If i wanted to index the letter 'w' in 'how' for the example above, then it would perform the following:
'hello ho
are you today'
I know this seems weird, but i am doing something much more complicated so understanding how to do this in an easy way would really help with my undrstanding.
Thank you and would really appreciate some help.
Best wishes
Respuesta aceptada
Más respuestas (1)
dpb
el 19 de Abr. de 2020
>> s= 'hello there how are you today';
>> strip(split(s,'w')) % if the location is a known character...
ans =
2×1 cell array
{'hello there ho'}
{'are you today' }
>>
>> ix=strfind('w'); % if must find the delimiter location
>> s(ix)=char(0); % insert delimiter and same song...
>> strip(split(s,char(0)))
ans =
2×1 cell array
{'hello there ho'}
{'are you today' }
>>
With more specifics on the actual application, possibly better techniques including bringing regular expressions into play might come to the fore...this is the simple, high-level ML functions approach.
1 comentario
Joe Wheatley
el 19 de Abr. de 2020
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!