[英]String replace with another character C#
我的消息通常在SMSgateway中出現(網關將消息轉發給我們的應用程序),
設置pØll12 3 4 5 6 7 8 121011(此消息是正確的)
但有些情況下這個消息就像,
sett p&oslas; ll 1 2 3 4 5 6 7 8 121011(此消息不正確,Ø附帶&oslas;)
消息來自&oslas時,此消息以字符串形式出現; 我需要將它更換為Ø。 有時它帶有另一個名字,比如gordØn(gord&oslas; n)它總是帶有&符號&endup的屬性; 標志。
在這里,我試圖這樣做,但我的知識還不足以完成這個..
protected void Page_Load(object sender, EventArgs e)
{
try
{
string mobileNo = Request.QueryString["msisdn"];
int dest = int.Parse(Request.QueryString["shortcode"].ToString());
string messageIn = Request.QueryString["msg"];
string operatorNew = Request.QueryString["operator"];
string []reparr = messageIn.Split(' ');//split it & then check contains
reparr[1].Contains = '&';
reparr[1].Contains = ';';
// In here i need to check that character & replace it to originalone.
Label1.Text = "ok";
WriteToFile(mobileNo, dest, messageIn, operatorNew,true,"","");
那些看起來像HTML實體。 您可以嘗試使用HttpUtility.HtmlDecode
解碼它們:
string messageIn = HttpUtility.HtmlDecode(Request.QueryString["msg"]);
您可以使用HttpServerUtility.UrlDecode解碼網址,請參閱http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.urldecode.aspx
我不知道Web命名空間實用程序,但您可以使用下面的代碼(如果&和;的位置始終位於消息的開頭,並且這些字符不會出現在消息文本中):
String s = @"sett p&oslas;ll 1 2 3 4 5 6 7 8 121011";
Int32 startIndex = s.IndexOf("&");
String s1 = s.Replace(s.Substring(startIndex, s.IndexOf(";") - startIndex + 1), "Ø");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.