Re: Swift: How to determine if a Character represents whitespace?
Re: Swift: How to determine if a Character represents whitespace?
- Subject: Re: Swift: How to determine if a Character represents whitespace?
- From: Quincey Morris <email@hidden>
- Date: Fri, 03 Apr 2015 03:16:52 +0000
On Apr 2, 2015, at 19:28 , Charles Jenkins <email@hidden> wrote:
>
> I can indeed call attrStr.string.rangeOfCharacterFromSet(). But in typical Swift string fashion, the return type is as unfriendly as possible: Range<String.Index>? — as if the NSString were a Swift string.
I finally read the whole of what you said here, and I had to run to a playground to check:
> import Cocoa
>
> var strA = "Hello?, String”
> var strB = "Hello?, String" as NSString
> var strC = "Hello\u{1f650}, String”
> var strD = "Hello\u{1f650}, NSString" as NSString
> var rangeA = strA.rangeOfCharacterFromSet(NSCharacterSet.whitespaceCharacterSet()) // {Some “7..<8”}
> var rangeB = strB.rangeOfCharacterFromSet(NSCharacterSet.whitespaceCharacterSet()) // (7,1)
> var rangeC = strC.rangeOfCharacterFromSet(NSCharacterSet.whitespaceCharacterSet()) // {Some “8..<9”}
> var rangeD = strD.rangeOfCharacterFromSet(NSCharacterSet.whitespaceCharacterSet()) // (8,1)
So, yes, these are NSString indexes all the way, even if the result is packaged as a Range<String.Index>.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden