目标C中的简单字符串连接 [英] Simple string concatenation in Objective C
本文介绍了目标C中的简单字符串连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为'you'的NSString,其值为"This is a you string!".
I have an NSString named 'you' with value "This is a you string!".
我要在"you"中添加"123",我该怎么办?
I want to concat "123" in 'you', how can I do it?
我正在使用此代码,它给出了一个错误.
I am using this code and it is giving an error.
you=[you stringByAppendingString:@"123"];
推荐答案
此处的代码对我有用
NSString *s = @"avant";
s = [s stringByAppendingString:@" - après"];
NSLog(@"%@", s);
2012-01-13 11:48:59.442 tabbar [604:207] avant-après
2012-01-13 11:48:59.442 tabbar[604:207] avant - après
所以我的猜测是您的you
是一个错误的指针,不是nil
而不是您认为的NSString.
So my guess is that your you
is a bad pointer that is not nil
and not the NSString you think it have.
在调用之前您是否尝试过对该值进行NSLog?
Have you try an NSLog on that value before the call?
这篇关于目标C中的简单字符串连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文