如何转义 NSString 以在 NSURL 中使用? [英] How to escape an NSString to use in NSURL?

查看:51
本文介绍了如何转义 NSString 以在 NSURL 中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止我的发送按钮得到了这个代码:

Got this code so far for my send button:

NSString* urlString = [NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", messageBox.text stringByAddingPercentEscapesUsingEncoding : NSUFT8StringEncoding];
NSURL *add = [NSURL URLWithString:urlString];

但是我确实收到错误预期的':'

However I do get the error "Expected ':'

推荐答案

需要将两个字符串构造调用分开

You need to separate the two string construction calls

NSString* urlString = [[NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", messageBox.text] stringByAddingPercentEscapesUsingEncoding : NSUTF8StringEncoding];
NSURL *add = [NSURL URLWithString:urlString];

这篇关于如何转义 NSString 以在 NSURL 中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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