> On 3 Sep 2016, at 16:23, Quincey Morris <quinceymor...@rivergatesoftware.com> 
> wrote:
> 
> On Sep 3, 2016, at 02:06 , Gerriet M. Denkmann <gerr...@mdenkmann.de> 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 how endIndex suddenly came into this.

I wanted to print some index with a format. 
let someIndex = someString.endIndex
let indexAsFormattedString = String(format: “%9d", someIndex )
But was told: error: argument type ‘Index' (aka 'String.CharacterView.Index’) 
does not conform to expected type 'CVarArgType'

So I did:
let indexAsString = String(someIndex)   //      ok
and tried to print indexAsString with a format.
This you helped me to do via:
let indexAsFormattedString = String(format: “%9s”, (indexAsString as 
NSString).utf8String )
Which works, because numbers are plain Ascii.


> Also, what are you expecting String (someString.endIndex) to be and/or mean?

It has the type ’String’ and contains a number in 0…someString.utf16.count .
It seems to be an index into the utf16 representation of the string. 
Which probably is an implementation detail not to be relied on, but somewhat 
useful for debugging.


But was really worries me is that fprintf can handle utf8String correctly even 
with non-Ascii, whereas [NSString stringWithFormat:] can not.


Kind regards,

Gerriet.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to