2013-04-16 63 views
0

我正在創建一個聊天應用程序。但是,現在我在發送特殊字符「&」時遇到了一個問題。我使用php web-services發送和接收消息,同時發送「&」字符,之後當有人收到這個字符時,應用程序崩潰。發送和接收特殊字符時應用程序崩潰

+0

後的崩潰報告..... – Venkat

回答

1

這裏替換其代碼像波紋管這個角色......

時傳在網絡服務在那個時候取代它像波紋管..

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

,然後當你想收到它在當時的特殊字符替換..

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

顯示後,在UITextViewUITextField

UPDATE:

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

UPDATE:

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

在發送字符串網絡serive使用波紋管strign ..

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? 
+0

我可以從我的設備發送成功,但是當我比收到回事崩潰 – Sonu

+0

請張貼一些代碼還有你從網上得到什麼?也打印該.. –

+0

***由於未捕獲異常'NSInvalidArgumentException',原因:'*** - [NSPlaceholderString initWithString:]:nil參數'終止應用程序***第一次拋出調用堆棧: (0x2428012 0x1bafe7e 0x2427deb 0x206f25 0x206ea4 0xdb0ac 0xd6b05 0x6888fb 0x6889cf 0x6711bb 0x681b4b 0x61e2dd 0x1bc36b0 0x13a0fc0 0x139533c 0x1395150 0x13130bc 0x1314227 0x13148e2 0x23f0afe 0x23f0a3d 0x23ce7c2 0x23cdf44 0x23cde1b 0x27ae7e3 0x27ae668 0x5cdffc 0x297d 0x28b5) 的libC++ abi.dylib:終止稱爲投擲從代碼和在那裏墜毀異常 – Sonu

相關問題