Re: formatted strings in Swift

2016-09-03 Thread Quincey Morris
On Sep 3, 2016, at 02:54 , Gerriet M. Denkmann 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

Re: formatted strings in Swift

2016-09-03 Thread Lou Zell
On Fri, Sep 2, 2016 at 10:02 PM, Gerriet M. Denkmann wrote: > > How to create a formatted string? > I use a little helper workaround that essentially looks like this: let str = "hi".nulTerminatedUTF8 let padded = str.withUnsafeBufferPointer() { return String(format:

Re: formatted strings in Swift

2016-09-03 Thread Quincey Morris
On Sep 3, 2016, at 02:06 , Gerriet M. Denkmann wrote: > > By the way: what I really wanted to do is: > let s = String(format: “%9d”, someString.endIndex ) I don’t understand this. Is %9d a typo for %9s? Or are we now talking about numbers instead of strings? I don’t get

Re: formatted strings in Swift

2016-09-03 Thread Gerriet M. Denkmann
> On 3 Sep 2016, at 14:52, Quincey Morris > wrote: > > The other issue I can think of would be how to interpret the field width, > since “real” strings can be counted in different ways. Would %9@ mean 9 > UTF-16 code units? 9 Unicode code points? 9

Re: formatted strings in Swift

2016-09-03 Thread Quincey Morris
On Sep 3, 2016, at 00:28 , Gerriet M. Denkmann wrote: > > I.e. the size parameter 9 seems to be ignored. (I kind of remember having the > same problem in Objective-C). Yes, it’s an issue with %@, which is a non-IEEE specifier, unlike %s, which is.

Re: formatted strings in Swift

2016-09-03 Thread Gerriet M. Denkmann
> On 3 Sep 2016, at 12:22, Quincey Morris > wrote: > > On Sep 2, 2016, at 22:02 , Gerriet M. Denkmann wrote: >> >> Did in a playground: >> >> let s = String(format: "%2s → %2s", "a", "b") >>

Re: formatted strings in Swift

2016-09-02 Thread Quincey Morris
On Sep 2, 2016, at 22:02 , Gerriet M. Denkmann wrote: > > Did in a playground: > > let s = String(format: "%2s → %2s", "a", "b") > print(“formatted = \"\(s)\"") > > But this prints random garbage (e.g.: formatted = “‡“S → ‡“S”) (no

formatted strings in Swift

2016-09-02 Thread Gerriet M. Denkmann
Did in a playground: let s = String(format: "%2s → %2s", "a", "b") print(“formatted = \"\(s)\"") But this prints random garbage (e.g.: formatted = “‡“S → ‡“S”) (no error message or compiler warning). Why? How to create a formatted string? Gerriet.