What characters are in whitespaceAndNewlineCharacterSet()?

前端 未结 2 1349
忘掉有多难
忘掉有多难 2021-01-29 03:24

I\'m parsing some nasty files - you know, mix comma, space and tab delimiters in a single line, and then run it through a text editor that word wraps at column 65 with

2条回答
  •  死守一世寂寞
    2021-01-29 03:52

    NSCharacterSet is an opaque class that does not expose its content easily. You have to see it more as a "membership" rule service than a list of characters.

    This may be a somewhat brutal approach, but you can get the list of members in an NSCharacterSet by going through all 16 bit scalar values and checking for membership in the set:

     let charSet = NSCharacterSet.whitespaceAndNewlineCharacterSet()
     for i in 0..<65536
     {
        let u:UInt16 = UInt16(i)
        if charSet.characterIsMember(u)
        { print("\(u): \(Character(UnicodeScalar(u)))") }
     }
    

    This gives surprising results for non-displayable character sets but it can probably answer your question.

提交回复
热议问题