如何从iphone中获取网络服务的% [英] how to get % from web-service in iphone

查看:102
本文介绍了如何从iphone中获取网络服务的%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iPhone开发的新手。我正在开发一个聊天应用程序。我在发送和接收一些特殊字符时遇到问题。最后,我成功发布并获得这个特殊字符。现在,只有一个特殊的我无法得到它的字符。当我向网络服务发送%时,我得到%25。

I'm new in iPhone development.I'm developing one chatting application.i was facing problem while sending and receiving some special character.finally, i succeeded to post and get this special character.now,there is only one special character which i'm not able to get it.while i'm sending % to the web-service,i get %25.

将字符串发送到网络服务器使用bellow string ..

At sending string to web-serive use bellow string..

NSString *string = @"Hello % How Are You?";
string = [string stringByReplacingOccurrencesOfString:@"%" withString:@"%25"];
NSLog(@"\n\n ===>> Before ==>> %@",string);
NSString *string2 = string;
string2 = [string2 stringByReplacingOccurrencesOfString:@"%25" withString:@"%"];
NSLog(@"\n\n ===>> After ==>> %@",string2);

OutPut =>

OutPut =>

===>> Before ==>> Hello%2520%2525%2520how%2520are%2520you?

 ===>> After ==>> Hello %2526 How Are You?


推荐答案

试试这段代码......

try this code...

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:@"&"];
string2 = [string2 stringByReplacingOccurrencesOfString:@"%25" withString:@"%"];    
NSLog(@"\n\n ===>> After ==>> %@",string2);

输出为:

===>> Before ==>> Hello%20%25%20How%20Are%20You?
====>> After ==>> Hello % How Are You?

这篇关于如何从iphone中获取网络服务的%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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