Regular Expression to append a string in text file

Here are some sentences from Text File.
hi where are you going.
hi how are you doing.
how are you.
hi where are you at this moment.
i want to replace '.' with '</s>'
so i am writing the following expression
  1. fid = fopen('Text_File.txt','w');
  2. f=fread(fid,'*char')';
  3. f = regexprep(f,'\.','</s>')
it is working perfectly BUT, i want to append a starting symbol at the beginning of sentences also that is '<s>', for that that i am using following one.
  1. f = regexprep(f,'^[]','<s>');
but it is not working what wrong i am doing.
PLZ answer thanks in advance.

 採用された回答

Cedric
Cedric 2013 年 10 月 8 日
編集済み: Cedric 2013 年 10 月 8 日

1 投票

Here is a simple and funny solution:
txt = regexprep( fileread('Text_File.txt'), '([^\n\r]+)', '$1' ) ;

その他の回答 (0 件)

カテゴリ

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

質問済み:

2013 年 10 月 8 日

編集済み:

2013 年 10 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by