[英]stringByAppendingPathComponent adds a '/' character to the text
I have the following code:我有以下代码:
NSString *message;
if (some_condition) {
message = @"String 1. ";
} else {
message = @"String 2. ";
}
message = [message stringByAppendingPathComponent:@"Bla bla bla."];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Alert"
message:message
preferredStyle:UIAlertControllerStyleAlert];
The text that I see when the alert pops up has an extra '/' character where the string were appended:我在弹出警报时看到的文本有一个额外的“/”字符,其中附加了字符串:
Where did it come from and how do I remove it?它是从哪里来的,我该如何删除它?
You are using the wrong method there.您在那里使用了错误的方法。
Instead of :代替 :
message = [message stringByAppendingPathComponent:@"Bla bla bla."];
Use:用:
message = [message stringByAppendingString:@"Bla bla bla."];
When you use stringByAppendingPathComponent:
it will return a new string made by appending the provided string to the receiver, preceded if necessary by a path separator.当您使用stringByAppendingPathComponent:
,它将返回一个通过将提供的字符串附加到接收器而形成的新字符串,如有必要,前面有一个路径分隔符。
Reference : NSString Class Reference参考: NSString 类参考
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.