2016-07-26 9 views
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"; 
+0

HMのようなEnvironment.NewLineプロパティを使用する - ちょうど基本:ほとんどの言語は、 '分割()'コマンドを提供します - "replace()"を使って通常の改行(\ n)を '" + \ n "'に置き換えます – Najzero

+0

これは通常テキストエディタを使って行いますが、ほとんどの高度なものはregexp find/replaceとマクロ。 –

+0

@ Najzeroありがとう、私は.replace( "\ n"、 "\\ n");しかし、正しくwokしていません –

答えて

0

文字列に+の代わりに\r\nというエスケープシーケンスを追加するだけです。参照: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" 

またはあなたがプログラミング言語を述べていなかったとして、

"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" 
+0

返信ありがとうが、私はJavaとジェーン文字列を使用していただきありがとうございます –

関連する問題