小编kob*_*chi的帖子

如何使用appendFormat格式化Swift中的字符串?

我想使用appendFormat将字符串附加到NSMutableString,插入空格以获得字符串的最小长度.

在objective-c中,我刚刚使用过

[text.mutableString appendFormat:@"%-12s", "MyString"];
Run Code Online (Sandbox Code Playgroud)

我会的

"MyString    "
Run Code Online (Sandbox Code Playgroud)

但在斯威夫特,我试过了

text.mutableString.appendFormat("%-12s", "MyString")
Run Code Online (Sandbox Code Playgroud)

我得到了一切,但不是"MyString".它似乎是一些随机字符,我不知道它来自哪里.

有没有人知道为什么会这样,我该怎么办?

感谢你们!

xcode nsmutablestring ios swift

9
推荐指数
2
解决办法
6427
查看次数

标签 统计

ios ×1

nsmutablestring ×1

swift ×1

xcode ×1