gpt4 book ai didi

ios - 如何在字符串 ios 中添加空格

转载 作者:行者123 更新时间:2023-11-29 02:22:52 26 4
gpt4 key购买 nike

我有一个用于 post 方法的字符串。如果字符串类似于 "hello.." 则值会在 post 方法中传递。但如果字符串类似于“hello world”,则不采用 post 方法。如果我在字符串中使用空格,它就不起作用。请帮助我。

- (void) constructURL
{
NSMutableString* curl = [[NSMutableString alloc] init];

[curl appendString:@"XXXXX"];
[curl appendString:[NSString stringWithFormat:@"?eventid=%@", eventID]];
[curl appendString:[NSString stringWithFormat:@"&ForumID=%@", forumID]];
[curl appendString:[NSString stringWithFormat:@"&parentPostID=%@", parentPostID]];
[curl appendString:[NSString stringWithFormat:@"&userid=%@", userID]];
[curl appendString:[NSString stringWithFormat:@"&PostContent=%@", postContent]];

url = [NSURL URLWithString:curl];
}

最佳答案

我认为你需要像这样编码你的字符串:

NSString* encodedString = [@"Hello World" stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];

关于ios - 如何在字符串 ios 中添加空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27921962/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com