最简单的方法来连接NSString和int [英] Easiest way to concatenate NSString and int

查看:114
本文介绍了最简单的方法来连接NSString和int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Objective-C中有一个通用函数,我可以插入我的项目,以简化 NSString s和 int s?

Is there a general purpose function in Objective-C that I can plug into my project to simplify concatenating NSStrings and ints?

推荐答案

如果要连接多个字符串和整数,请使用NSMutableString的appendFormat。

Both answers are correct. If you want to concatenate multiple strings and integers use NSMutableString's appendFormat.

NSMutableString* aString = [NSMutableString stringWithFormat:@"String with one int %d", myInt];    // does not need to be released. Needs to be retained if you need to keep use it after the current function.
[aString appendFormat:@"... now has another int: %d", myInt];

这篇关于最简单的方法来连接NSString和int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆