• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Swift: How to determine if a Character represents whitespace?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Swift: How to determine if a Character represents whitespace?
      • From: Charles Jenkins <email@hidden>
References: 
 >Swift: How to determine if a Character represents whitespace? (From: Charles Jenkins <email@hidden>)
 >Re: Swift: How to determine if a Character represents whitespace? (From: Charles Srstka <email@hidden>)
 >Re: Swift: How to determine if a Character represents whitespace? (From: Charles Jenkins <email@hidden>)
 >Re: Swift: How to determine if a Character represents whitespace? (From: Quincey Morris <email@hidden>)
 >Re: Swift: How to determine if a Character represents whitespace? (From: Charles Jenkins <email@hidden>)
 >Re: Swift: How to determine if a Character represents whitespace? (From: Quincey Morris <email@hidden>)
 >Re: Swift: How to determine if a Character represents whitespace? (From: Charles Jenkins <email@hidden>)

  • Prev by Date: Re: Swift: How to determine if a Character represents whitespace?
  • Next by Date: Do NSStackView's actually work in a NSTableView?
  • Previous by thread: Re: Swift: How to determine if a Character represents whitespace?
  • Next by thread: Re: Swift: How to determine if a Character represents whitespace?
  • Index(es):
    • Date
    • Thread