Ich habe eine Zeichenfolge wie folgt:Entfernen Zeilenumbrüche aus string
var aString = "This is a string \n\n This is the second line of the string\n\n"
, die in einem Textview wie so aussieht:
This is a string
This is the second line of the string
// 2 extra lines of unnecessary white space
Aber ich will es so aussehen:
This is a string
This is the second line of the string
Ich möchte alle "\ n" vom Ende der Zeichenfolge entfernen und entfernen \ n, wo es sich wiederholt, so dass es keinen Leerraum in der Mitte gibt.
ideal, ich bin das Endergebnis erraten sollte dies sein:
var aString = "This is a string \n This is the second line of the string"
Was haben Sie versucht? Haben Sie das '/ n/n' mit'/n' ersetzt? Http://stackoverflow.com/questions/24200888/any-way-to-replace-characters-on-swift-string oder sogar '/ n/n 'mit'/n', um den zusätzlichen Speicherplatz zu entfernen. Obwohl das ein wenig vereinfacht sein könnte – Flexicoder
http://stackoverflow.com/questions/28957940/remove-all-line-breaks-at-the-beginn-of-a-string-in-swift –
Sind Sie sicher, dass es nicht ist \ n'? – Sulthan