How to replace all newline characters in a string with a space?

34 ビュー (過去 30 日間)
John Jamieson
John Jamieson 2020 年 11 月 29 日
回答済み: Steven Lord 2020 年 11 月 29 日
I want to replace all newline characters in an inputted string of characters "strtxt" with spaces. However, I've no idea how to isolate these newline characters using a built-in function such as strfind in order to replace them. How would I do this by somehow utilising strfind, and not bu using an already built in function made for this specific type of problem?

回答 (2 件)

Walter Roberson
Walter Roberson 2020 年 11 月 29 日
strfind(strtxt, 10)
will return the indices.
Hint:
S = "hello"
S{1}(1) = 'j'

Steven Lord
Steven Lord 2020 年 11 月 29 日
Since this sounds like it may be a homework assignment, I'll only give a hint. There's one function in the "Create, Concatenate, and Convert" section and one function in the "Find and Replace" section on this documentation page that may be useful.

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by