gpt4 book ai didi

iphone - 应用程序在发送和接收特殊字符时崩溃

转载 作者:行者123 更新时间:2023-11-29 03:59:47 26 4
gpt4 key购买 nike

我正在创建一个聊天应用程序。但是,现在我在发送特殊字符“&”时遇到一个问题。我正在使用 php Web 服务发送和接收消息。在发送“&”字符时,之后当有人收到此字符时,应用程序崩溃。

最佳答案

在这里用下面的代码替换该字符...

当将其传递到网络服务时,请像下面这样替换它..

yourString = [yourString stringByReplacingOccurrencesOfString:@"&" withString:@"&"];

然后当你想接收它的时候用特殊字符替换..

    yourString = [yourString stringByReplacingOccurrencesOfString:@"&" withString:@"&"];

UITextViewUITextField 中显示后

更新:

if (string2 != nil) {
string1 = [NSString stringWithString:string2];
NSString *strTemp = [NSString stringWithString:string2];
NSLog(@"\n\n Temp String ==>> %@",strTemp);
}

更新:

 NSString *yourString = @"Hello & How Are You?";
yourString = [yourString stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
NSLog(@"\n\n String Here => %@",yourString);

在将字符串发送到网络服务器时,请使用以下字符串..

NSString *yourStringForWeb = @"Hello & How Are You?";
yourStringForWeb = [yourStringForWeb stringByReplacingOccurrencesOfString:@"&" withString:@"&"];

并将此 yourStringForWeb 传递给网络服务...

NSString *string = @"Hello & How Are You?";

string = [string stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
string = [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
string = [string stringByReplacingOccurrencesOfString:@"&" withString:@"%26"];
NSLog(@"\n\n ===>> Before ==>> %@",string);

NSString *string2 = string;

string2 = [string2 stringByReplacingOccurrencesOfString:@"%20" withString:@" "];
string2 = [string2 stringByReplacingOccurrencesOfString:@"%26" withString:@"&"];
NSLog(@"\n\n ===>> After ==>> %@",string2);

输出=>

 ===>> Before ==>> Hello%20%26%20How%20Are%20You?
===>> After ==>> Hello & How Are You?

关于iphone - 应用程序在发送和接收特殊字符时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16029076/

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