Replace a single character with a new line in a string
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
dpb
2020년 4월 19일
>> 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.
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!