How can I remove the extra blank spaces from a text?
12 ビュー (過去 30 日間)
古いコメントを表示
For example, I have the sentence ' I will go to the cinema' . I need this sentence to be written as 'I will go to the cinema'. I need to delete the extras spaces.
0 件のコメント
回答 (1 件)
Geoff Hayes
2022 年 5 月 3 日
@Tiziano dos Santos - you could perhaps use strsplit to split the string on the space character and will create a cell array of strings (the words from your sentence). You could then use join to combine the words with a space between each one (may also need to trim the string first).
There is also probably a clever (better way to do this using) regexprep command that will do the same thing. I tried it and it wasn't too difficult to do.
2 件のコメント
Walter Roberson
2022 年 5 月 3 日
S = ' I will go to the cinema'
newS = regexprep(strtrim(S), '\s+', ' ')
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!