我有这样的事情:
我的应用程序有NSTextfield
名为userName,NSTextfield
名为helloName,NSButton
启动整个过程。它只是用户在名称文本字段中输入他/她的名字。
当用户按下确认时,Hello文本字段将显示“Hello,userName”之类的内容,而userName是直接从Name文本字段中获取的字符串。
我知道有一种方法可以从Name文本字段中获取字符串值,并使用%@
将该值添加到句子“Hello,userName”中。但我无法在任何地方找到它......
答案 0 :(得分:2)
您正在寻找[NSString stringWithFormat:]
NSString* helloSentence = [NSString stringWithFormat:@"Hello, %@", [userName stringValue];