2
let splitLines = line.split(separator: "\u{e2}")

case "\u{e2}":
                print("FoundBadReturn")

let newText = text.replacingOccurrences(of: "\u{e2}", with: "\n")

I'm working with a RTF Document in UITextView. I'm trying to change Strings that contain \u{e2} char with \n None of these lines seem to work against Strings

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116

3 Answers3

5

The debugger print is misleading. The character is "\u{2028}" 'Line Separator' rather than "\u{e2}". The debugger does this because 0xE2 is the first byte of that character in UTF8, and it hides the rest. If you instead try to perform your operations (delete, replace, contains...) on "\u{2028}", they will work.

entonio
  • 2,143
  • 1
  • 17
  • 27
3

Have you tried the solution here? It works for me. https://stackoverflow.com/a/47835062/

phoneLabel.text?.replacingOccurrences(of: "\\p{Cf}", with: "", options: .regularExpression)
royh
  • 51
  • 2
  • When copy phone number from `Phone` app, debuger show `\u{e2}`, but the real is: `\\p{Cf}` :)) – lee Jun 16 '20 at 07:01
0

I wrote the following function to solve this problem. It's probably not the best solution.

func splitOnAlternateNewline(line: String) -> [String]{
    var returnArray: [String] = []
    var aString = ""
    outLoop :for char in line{
        let aChar = String(char).utf16
        for a in aChar{
            if a == 8232{
                returnArray.append(aString)
                aString = ""
                continue outLoop

            }

        }
        aString.append(char)


    }
    returnArray.append(aString)
    return returnArray

}