0

文字列をフォーマットされた文字列に変換するにはどうすればよいですか

私が持っている次の文字列

"It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us"

このように文字列の上に変換する必要があります

"It was the best of times, it was the worst of times,\\n" +
" it was the age of wisdom, it was the age of foolishness,\\n" +
" it was the epoch of belief, it was the epoch of incredulity,\\n" +
" it was the season of Light, it was the season of Darkness,\\n" +
" it was the spring of hope, it was the winter of despair,\\n" +
" we had everything before us, we had nothing before us";
4

1 に答える 1

0

\r\n文字列の代わりにa を使用してエスケープ シーケンスを追加するだけ+です。参照: https://msdn.microsoft.com/en-us/library/h21280bw.aspx

"It was the best of times, it was the worst of times,\r\n
  it was the age of wisdom, it was the age of foolishness,\r\n
  it was the epoch of belief, it was the epoch of incredulity,\r\n
  it was the season of Light, it was the season of Darkness,\r\n
  it was the spring of hope, it was the winter of despair,\r\n
  we had everything before us, we had nothing before us"

または Environment.NewLine プロパティを次のように使用します

"It was the best of times, it was the worst of times," + Environment.NewLine
+ " it was the age of wisdom, it was the age of foolishness," + Environment.NewLine 
+ " it was the epoch of belief, it was the epoch of incredulity," + Environment.NewLine 
+ " it was the season of Light, it was the season of Darkness," + Environment.NewLine 
+ " it was the spring of hope, it was the winter of despair," + Environment.NewLine  
+ " we had everything before us, we had nothing before us"
于 2016-07-26T09:07:49.440 に答える