使用 stringByAppendingString 将字符添加到 Xcode/objective-C 中的现有字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9751954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using stringByAppendingString to add character to existing string in Xcode/objective-C
提问by AdamL
I am trying to add the character "1" to the existing value of a textbox "output" in Xcode objective-C.
我正在尝试将字符“1”添加到 Xcode Objective-C 中文本框“输出”的现有值中。
I am trying to use the "stringByAppendingString" function, and have looked at some examples and can't seem to get this to work.
我正在尝试使用“stringByAppendingString”函数,并且查看了一些示例,但似乎无法使其正常工作。
Is my syntax just wrong?
我的语法是错误的吗?
- (IBAction)pressOne:(id)sender {
NSString *str1 = output.text;
output.text = [str1 stringByAppendingString:[@"1"];
}
采纳答案by jlehr
Get rid of the stray bracket before the @
symbol:
去掉@
符号前的杂散括号:
output.text = [str1 stringByAppendingString:@"1"];
回答by sooper
try [str1 stringByAppendingString:@"1"];
尝试 [str1 stringByAppendingString:@"1"];
回答by sch
Remove the brackets:
去掉括号:
output.text = [str1 ?stringByAppendingString:@"1"];