How can i convert multiples lines into 1 text string (big block)

so my file is like:
abcdef
abcdef
abcdef
abcdef
and i would like them to be in 1 text string without enters: 'abcdefabcdefabcdefabcdef'

回答 (2 件)

Stephen23
Stephen23 2016 年 4 月 22 日
編集済み: Stephen23 2016 年 4 月 22 日

1 投票

To remove all whitespaces within the text:
str = regexprep(fileread('temp.txt'),'\s+','')
Or to only remove newlines and carriage return characters:
str = regexprep(fileread('temp.txt'),'[\n\r]+','')
I tested these on this file:
J. Webster
J. Webster 2016 年 4 月 22 日

0 投票

file = textread('text.txt', '%s', 'whitespace','');
file will be a cell array containing the string you want.

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

製品

質問済み:

2016 年 4 月 22 日

編集済み:

2016 年 4 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by