• 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: formatted strings in Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: formatted strings in Swift


  • Subject: Re: formatted strings in Swift
  • From: Quincey Morris <email@hidden>
  • Date: Sat, 03 Sep 2016 10:26:04 -0700
  • Feedback-id: 167118m:167118agrif8a:167118snOXEO4QuZ:SMTPCORP

On Sep 3, 2016, at 02:54 , Gerriet M. Denkmann <email@hidden> wrote:
>
> I wanted to print some index with a format.

OIC.

Your solution doesn’t work in Swift 3, because the String.init (_:) method has been renamed to String.init (describing:), and actually produces a textual description of the string index:

	Index(_base: Swift.String.UnicodeScalarView.Index(_position: 1), _countUTF16: 0)

However, if you want to format the number of characters in a string, you can do it directly like this:

	let a = "a"
	let s = String (format: "ť", a.characters.count) // “characters” mean grapheme clusters in Swift
	print (s) // -> "        1”

Or you can use a.unicodeScalars.count (for counting code points), or a.utf16.count (for counting UTF-16 code units), if one of those is the count you want instead.

_______________________________________________

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


References: 
 >formatted strings in Swift (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: formatted strings in Swift (From: Quincey Morris <email@hidden>)
 >Re: formatted strings in Swift (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: formatted strings in Swift (From: Quincey Morris <email@hidden>)
 >Re: formatted strings in Swift (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: formatted strings in Swift (From: Quincey Morris <email@hidden>)
 >Re: formatted strings in Swift (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: formatted strings in Swift
  • Next by Date: Get file argument
  • Previous by thread: Re: formatted strings in Swift
  • Next by thread: Re: formatted strings in Swift
  • Index(es):
    • Date
    • Thread