2016-07-26 14 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

흠 같이 Environment.NewLine 속성을 사용합니다 - 그냥 기본을 : 참조 : 대부분의 언어는 '분할()'명령을 제공합니다 - 또는'replace()'를 사용하여 보통의 줄 바꿈 (\ n)을''\ n "'으로 바꾸십시오. – Najzero

+0

이것은 대개 텍스트 편집기를 사용하여 수행되며 대부분 고급 항목은 regexp 찾기/바꾸기를 지원합니다 및 매크로. –

+0

@ Najzero 덕분에 나는 .replace ("\ n", "\\ n"); 하지만 제대로 웍을 –

답변

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

답장을 주셔서 감사하지만 메신저 자바와 제온을 사용하여 –