0

我的消息通常在 SMSgateway 中是这样的(网关将消息转发到我们的应用程序),

sett pØll 1 2 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) 它总是以 & 符号 & 结束 ; 符号。

在这里我尝试做到这一点,但我的知识不足以完成这个..

 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,"","");
4

3 回答 3

2

这些看起来像 HTML 实体。您可以尝试使用以下方法对它们进行解码HttpUtility.HtmlDecode

string messageIn = HttpUtility.HtmlDecode(Request.QueryString["msg"]);
于 2012-10-14T18:52:50.843 回答
0

I am not aware about web namespace utilities but you may use below code (if position of & and ; is always going to be in beginning of message and these characters will not appear inside message text):

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), "Ø");
于 2012-10-14T19:04:12.860 回答
0

您可以使用 HttpServerUtility.UrlDecode 来解码 url 参见http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.urldecode.aspx

于 2012-10-14T18:54:51.753 回答