如何组合两个NSString?
我有以下两个 NSString
:
NSString *latitudeString, *longitudeString;
latitudeString = @"50.1338";
,
longitudeString = @"8.91583";
我想要获取的是一个如下所示的 NSString:50.1338,8.91583。
我如何获得它?谢谢
重要提示:我显示的值只是为了更好地理解,通常 latitudeString
和 longitudeString
具有随机值。
I have the following two NSString
:
NSString *latitudeString, *longitudeString;
latitudeString = @"50.1338";
and
longitudeString = @"8.91583";
What I want to obtain is a NSString that looks like this: 50.1338,8.91583.
How do I obtain that?Thanks
IMPORTANT: The values I showed are only for the purpose of better understanding, ussually latitudeString
and longitudeString
have random values.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
为了得到你想要的,你可以使用
To get what you want you can use
只需使用 stringWithFormat 方法
Just use stringWithFormat method
迟了一千年:
会稍微降低运行时解析成本,并且从历史上看,会给您带来更高的类型安全性(在编译器检查类型字符串之前)。因此,我们中的一些老手已经习惯了它,但仍然在心理上以相当微弱的性能论点来证明舒适的合理性。
如果您宁愿在缺少一个字符串时引发异常,也不愿默默地产生一些无意义的东西,这也可能是更好的选择。
A thousand years late:
Would slightly reduce runtime parsing costs and, historically, would have given you greater type safety (before the compiler checked type strings). So some of us old timers got used to it and still mentally make the fairly feeble performance argument to justify what's comfortable.
May also be preferable if you'd rather raise an exception upon one string being missing than silently produce something nonsensical.
试试这个
Try this
也许这样更好:
Maybe it was better:
[NSString stringWithFormat:@"%@,%@",latitudeString,longitudeString];
[NSString stringWithFormat:@"%@,%@",latitudeString,longitudeString];