如何在字符串中将一个char添加到许多其他char中 [英] How do I repleace one char to many others in a string

查看:102
本文介绍了如何在字符串中将一个char添加到许多其他char中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!



我有一个字符串,包含很多空格,我需要将空格字符更改为%20。



THX任何帮助!

Hi!

I have a string, witch contains many spaces, I need to change the space characters to %20.

THX for any help!

推荐答案

一般情况下,你只需使用 string.Replace

http:// msdn .microsoft.com / zh-cn / library / czx8s9ts(v = vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/fk49wtc1(v = vs.110)的.aspx [< a href =http://msdn.microsoft.com/en-us/library/fk49wtc1(v=vs.110).aspx\"target =_ blanktitle =New Window> ^ ]。



但我几乎可以肯定你真正需要的不是你所要求的。最有可能的是,您不仅需要编码空格,还需要编码URL中不允许的所有内容。请参阅:

http://en.wikipedia.org/wiki/Percent-encoding [ ^ ]。



这是如何: http:/ /msdn.microsoft.com/en-us/library/zttxte6w%28v=vs.110%29.aspx [ ^ ]。



-SA
In general case, you just use string.Replace:
http://msdn.microsoft.com/en-us/library/czx8s9ts(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/fk49wtc1(v=vs.110).aspx[^].

But I am nearly sure that what you really need is not what you are asking for. Most likely, you need to encode not only spaces, but everything which is not allowed in URL. Please see:
http://en.wikipedia.org/wiki/Percent-encoding[^].

This is how: http://msdn.microsoft.com/en-us/library/zttxte6w%28v=vs.110%29.aspx[^].

—SA


有很多方法,但最简单的方法可能是:

There are loads of ways, but the simplest might be:
string output = input.Replace(" ", "%20");


这篇关于如何在字符串中将一个char添加到许多其他char中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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