0

my messages normally comes like this in SMSgateway(gateway forwarded the message to our application),

sett pØll 1 2 3 4 5 6 7 8 121011 ( this message is correct )

But some cases this message comes like,

sett p&oslas;ll 1 2 3 4 5 6 7 8 121011 (this message incorrect,Ø comes with &oslas;)

this message comes as a string,when message comes &oslas; i need to replace it to Ø. sometimes it comes with another name, like gordØn(gord&oslas;n) It always stat with & sign & endsup with ; sign.

Here i tries to do it,but my knowledge is not enough to complete this..

 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,"","");
2
  • I mean, you can conceivably do messageIn.Replace("&oslas;", "ø");, but I think that using HtmlDecode is more flexible. Commented Oct 14, 2012 at 19:08
  • when i add HtmlDecode then after the &, all the character missing. Commented Oct 15, 2012 at 4:03

3 Answers 3

2

Those look like HTML entities. You can try to decode them using HttpUtility.HtmlDecode:

string messageIn = HttpUtility.HtmlDecode(Request.QueryString["msg"]);
Sign up to request clarification or add additional context in comments.

5 Comments

i think you can't use this function,OP needs String replace
he ask about when some character inside the &xxxx; then how to replace with original Ø; character
Yes, but &xxxx; are commonly known as HTML entities. Since he gets the data from a web form, it makes sense that the input might contain HTML entities. Using a library function is much easier than trying to deal with the hundreds of defined HTML entities.
@nneonneo ya then how to replace it with original characters ?
@NimanthaPrasad: That's what HtmlDecode does: it takes stuff like %amp; and ø and replaces it with the proper characters & and ø.
0

you can use HttpServerUtility.UrlDecode to decode the url see http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.urldecode.aspx

4 Comments

That seems to be the wrong function; it decodes URLs (%20), not HTML entities (&).
querystring is supposed to be from url.
he ask about when some character inside the &xxxx; then how to replace with original Ø character
@ChathuraRanasinghe Ranasinghe ya.exactly that i need.In here there's no any problem with query string
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), "Ø");

2 Comments

So, what happens if there are two Ø in the text?
OP didn't explain anything related to this. OP is expecting Ø character to be missing when invalid value is coming and if Ø is coming then value is valid. Of course the code will need to handle all the scenarios.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.