2016-07-26 6 views
0

Wie kann ich Zeichenfolge in formatierten StringWie wie normale String-Umwandlung in mehrzeiligen String

folgende Zeichenfolge konvertieren Ich habe

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

Ich habe zu konvertieren über String wie dieser

"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 verwenden, da Sie keine Programmiersprache angegeben hätten - nur die Grundlagen: Die meisten Sprachen bieten ein 'split()' Befehl - Oder du verwendest 'replace()' ..., um einen normalen Zeilenumbruch (\ n) durch '" + \ n "' – Najzero

+0

zu ersetzen. Dies wird normalerweise mit Hilfe eines Texteditors gemacht, die meisten der fortgeschrittenen unterstützen regexp find/replace und Makros. –

+0

@Najzero danke und ich verwendet .replace ("\ n", "\\ n"); aber nicht wok richtig –

Antwort

0

Fügen Sie einfach eine Escape-Sequenz mit einem \r\n statt + in Ihrer Zeichenfolge hinzu. Siehe auch: 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" 

oder Environment.NewLine Immobilien wie

"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

danke für die antwort, aber ich benutze java und jeson String –

Verwandte Themen