Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem to convert my code and don't know how to search for it over google

Problem to convert my code and don't know how to search for it over google

Scheduled Pinned Locked Moved C#
helptutorialquestion
11 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Naveed727
    wrote on last edited by
    #1

    Hello, I have a very simple problem but I don't now how to search about this on Google. I have a url I don't know it is in Unicode or what I am pasting it please if any one help me regarding this. חברות-תיירות actually this is a part of url and I have to convert it to such coding to let my browser to understand it and I can use it. Yes I know about HttpUtility.UrlDecode but as I told you earlier I don't know in which coding is my string, most when I paste my string in google and write that I want to decode it, google automatically convert it to original language, I want the same thing which google is doing but how? Please help me out guys because I spend about 2 hours on this issue but no success. Thanks in advance

    L N L 5 Replies Last reply
    0
    • N Naveed727

      Hello, I have a very simple problem but I don't now how to search about this on Google. I have a url I don't know it is in Unicode or what I am pasting it please if any one help me regarding this. חברות-תיירות actually this is a part of url and I have to convert it to such coding to let my browser to understand it and I can use it. Yes I know about HttpUtility.UrlDecode but as I told you earlier I don't know in which coding is my string, most when I paste my string in google and write that I want to decode it, google automatically convert it to original language, I want the same thing which google is doing but how? Please help me out guys because I spend about 2 hours on this issue but no success. Thanks in advance

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I'm not sure quite what you are trying to do, but is it to display that string? Something like (I just threw this into a page of an MVC3 page to quickly test, but you can probably follow what I mean). It displays a Hebrew string - if that is what you are trying to do. But I may have interpreted you wrongly.

      <p lang="he">@Html.Raw(@HttpUtility.HtmlDecode("&#1495;&#1489;&#1512;&#1493;&#1514;-&#1514;&#1497;&#1497;&#1512;&#1493;&#1514;"))</p>

      N 1 Reply Last reply
      0
      • L Lost User

        I'm not sure quite what you are trying to do, but is it to display that string? Something like (I just threw this into a page of an MVC3 page to quickly test, but you can probably follow what I mean). It displays a Hebrew string - if that is what you are trying to do. But I may have interpreted you wrongly.

        <p lang="he">@Html.Raw(@HttpUtility.HtmlDecode("&#1495;&#1489;&#1512;&#1493;&#1514;-&#1514;&#1497;&#1497;&#1512;&#1493;&#1514;"))</p>

        N Offline
        N Offline
        Naveed727
        wrote on last edited by
        #3

        http://easy.co.il[^]Thanks for reply No am not trying to display this string my page. Let me explain it again. Following (1) and (2) is example I have an url : (1) [http://easy.co.il/&amp;#1495;&amp;#1489;&amp;#1512;&amp;#1493;&amp;#1514;-&amp;#1514;&amp;#1497;&amp;#1497;&amp;#1512;&amp;#1493;&amp;#1514;/](http://easy.co.il/&amp;#1495;&amp;#1489;&amp;#1512;&amp;#1493;&amp;#1514;-&amp;#1514;&amp;#1497;&amp;#1497;&amp;#1512;&amp;#1493;&amp;#1514;/)[[^](http://easy.co.il/&amp;#1495;&amp;#1489;&amp;#1512;&amp;#1493;&amp;#1514;-&amp;#1514;&amp;#1497;&amp;#1497;&amp;#1512;&amp;#1493;&amp;#1514;/ "New Window")] I want to convert it to (2) [http://easy.co.il/%D7%97%D7%91%D7%A8%D7%95%D7%AA-%D7%AA%D7%99%D7%99%D7%A8%D7%95%D7%AA/](http://easy.co.il/%D7%97%D7%91%D7%A8%D7%95%D7%AA-%D7%AA%D7%99%D7%99%D7%A8%D7%95%D7%AA/)[[^](http://easy.co.il/%D7%97%D7%91%D7%A8%D7%95%D7%AA-%D7%AA%D7%99%D7%99%D7%A8%D7%95%D7%AA/ "New Window")] As you can see (1) if I past it in browser it is not working and (2) is working fine. So now I have a lot of urls like (1) and I have to convert them in to (2). Please help me how I will do this conversion.

        1 Reply Last reply
        0
        • N Naveed727

          Hello, I have a very simple problem but I don't now how to search about this on Google. I have a url I don't know it is in Unicode or what I am pasting it please if any one help me regarding this. &amp;#1495;&amp;#1489;&amp;#1512;&amp;#1493;&amp;#1514;-&amp;#1514;&amp;#1497;&amp;#1497;&amp;#1512;&amp;#1493;&amp;#1514; actually this is a part of url and I have to convert it to such coding to let my browser to understand it and I can use it. Yes I know about HttpUtility.UrlDecode but as I told you earlier I don't know in which coding is my string, most when I paste my string in google and write that I want to decode it, google automatically convert it to original language, I want the same thing which google is doing but how? Please help me out guys because I spend about 2 hours on this issue but no success. Thanks in advance

          N Offline
          N Offline
          Naveed727
          wrote on last edited by
          #4

          Please help me out , I am not able to solve this problem. :((

          1 Reply Last reply
          0
          • N Naveed727

            Hello, I have a very simple problem but I don't now how to search about this on Google. I have a url I don't know it is in Unicode or what I am pasting it please if any one help me regarding this. &amp;#1495;&amp;#1489;&amp;#1512;&amp;#1493;&amp;#1514;-&amp;#1514;&amp;#1497;&amp;#1497;&amp;#1512;&amp;#1493;&amp;#1514; actually this is a part of url and I have to convert it to such coding to let my browser to understand it and I can use it. Yes I know about HttpUtility.UrlDecode but as I told you earlier I don't know in which coding is my string, most when I paste my string in google and write that I want to decode it, google automatically convert it to original language, I want the same thing which google is doing but how? Please help me out guys because I spend about 2 hours on this issue but no success. Thanks in advance

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Hi, I wrote a little decoder for it:

            string s1="this is to be the input string, however the CP message editor page does not like Unicode";
            string s2="";
            for (int i=0; iLuc Pattyn [\[Forum Guidelines\]](/KB/scrapbook/ForumGuidelines.aspx) [\[My Articles\]](http://www.perceler.com/articles1.php) Nil Volentibus Arduum
            

            Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

            1 Reply Last reply
            0
            • N Naveed727

              Hello, I have a very simple problem but I don't now how to search about this on Google. I have a url I don't know it is in Unicode or what I am pasting it please if any one help me regarding this. &amp;#1495;&amp;#1489;&amp;#1512;&amp;#1493;&amp;#1514;-&amp;#1514;&amp;#1497;&amp;#1497;&amp;#1512;&amp;#1493;&amp;#1514; actually this is a part of url and I have to convert it to such coding to let my browser to understand it and I can use it. Yes I know about HttpUtility.UrlDecode but as I told you earlier I don't know in which coding is my string, most when I paste my string in google and write that I want to decode it, google automatically convert it to original language, I want the same thing which google is doing but how? Please help me out guys because I spend about 2 hours on this issue but no success. Thanks in advance

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              and this is a lot safer already:

              string s1="the input string";
              s1=HttpUtility.HtmlDecode(s1);
              string s2="";
              for (int i=0; i<s1.Length; i++) {
              if (s1[i]=='&' && s1[i+1]=='#') {
              i+=2;
              int n=0;
              for (; ; ) {
              char c=s1[i++];
              int k="0123456789".IndexOf(c);
              if (k<0) break; // break on non-digit
              n=10*n+k;
              }
              s2+=(char)n;
              i--;
              } else {
              s2+=s1[i];
              }
              }
              log("s1="+s1);
              log("s2="+s2);

              :)

              Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

              modified on Wednesday, April 6, 2011 6:30 AM

              N 1 Reply Last reply
              0
              • L Luc Pattyn

                and this is a lot safer already:

                string s1="the input string";
                s1=HttpUtility.HtmlDecode(s1);
                string s2="";
                for (int i=0; i<s1.Length; i++) {
                if (s1[i]=='&' && s1[i+1]=='#') {
                i+=2;
                int n=0;
                for (; ; ) {
                char c=s1[i++];
                int k="0123456789".IndexOf(c);
                if (k<0) break; // break on non-digit
                n=10*n+k;
                }
                s2+=(char)n;
                i--;
                } else {
                s2+=s1[i];
                }
                }
                log("s1="+s1);
                log("s2="+s2);

                :)

                Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                modified on Wednesday, April 6, 2011 6:30 AM

                N Offline
                N Offline
                Naveed727
                wrote on last edited by
                #7

                thank you very much, It really help me out. Thanks again.

                L 1 Reply Last reply
                0
                • N Naveed727

                  thank you very much, It really help me out. Thanks again.

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  You're welcome. :)

                  Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                  1 Reply Last reply
                  0
                  • N Naveed727

                    Hello, I have a very simple problem but I don't now how to search about this on Google. I have a url I don't know it is in Unicode or what I am pasting it please if any one help me regarding this. &amp;#1495;&amp;#1489;&amp;#1512;&amp;#1493;&amp;#1514;-&amp;#1514;&amp;#1497;&amp;#1497;&amp;#1512;&amp;#1493;&amp;#1514; actually this is a part of url and I have to convert it to such coding to let my browser to understand it and I can use it. Yes I know about HttpUtility.UrlDecode but as I told you earlier I don't know in which coding is my string, most when I paste my string in google and write that I want to decode it, google automatically convert it to original language, I want the same thing which google is doing but how? Please help me out guys because I spend about 2 hours on this issue but no success. Thanks in advance

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    A bit ugly, but seems to work...

                        private static void TestDecode()
                        {
                            UTF8Encoding enc = new System.Text.UTF8Encoding();
                            string output = "";
                            string smain = "&amp;#1495;&amp;#1489;&amp;#1512;&amp;#1493;&amp;#1514;-&amp;#1514;&amp;#1497;&amp;#1497;&amp;#1512;&amp;#1493;&amp;#1514;";
                            int len = smain.Length;
                            int pos = 0; 
                            uint acode = 0;
                            while (pos < smain.Length)
                            {
                                int pos2 = -1;
                                if (smain.Length >= pos + 7 && smain.Substring(pos,6) == "&amp;#")
                                {
                                    // We have a position starting with %amp;# so now find next ;
                                    pos2 = smain.IndexOf(";",pos + 6);
                                }
                                // If there is at least one character between # and ; and it is numeric...
                                if (pos2 >= pos + 7 && uint.TryParse(smain.Substring(pos + 6, pos2 - pos - 6), out acode))
                                {
                                    char\[\] c = { Convert.ToChar(acode) };
                                    byte\[\] b = enc.GetBytes(c);
                                    for (int i = 0; i < b.Length; i++)
                                    {
                                        output += String.Format("%{0:x2}", b\[i\]).ToUpper();
                                    }
                                    // Advance to pos after ;
                                    pos = pos2 + 1;
                                }
                                else
                                {
                                    output += smain\[pos\];
                                    pos += 1;
                                }
                            }
                            Console.WriteLine(output);
                         }
                    

                    modified on Wednesday, April 6, 2011 7:05 AM

                    N 1 Reply Last reply
                    0
                    • L Lost User

                      A bit ugly, but seems to work...

                          private static void TestDecode()
                          {
                              UTF8Encoding enc = new System.Text.UTF8Encoding();
                              string output = "";
                              string smain = "&amp;#1495;&amp;#1489;&amp;#1512;&amp;#1493;&amp;#1514;-&amp;#1514;&amp;#1497;&amp;#1497;&amp;#1512;&amp;#1493;&amp;#1514;";
                              int len = smain.Length;
                              int pos = 0; 
                              uint acode = 0;
                              while (pos < smain.Length)
                              {
                                  int pos2 = -1;
                                  if (smain.Length >= pos + 7 && smain.Substring(pos,6) == "&amp;#")
                                  {
                                      // We have a position starting with %amp;# so now find next ;
                                      pos2 = smain.IndexOf(";",pos + 6);
                                  }
                                  // If there is at least one character between # and ; and it is numeric...
                                  if (pos2 >= pos + 7 && uint.TryParse(smain.Substring(pos + 6, pos2 - pos - 6), out acode))
                                  {
                                      char\[\] c = { Convert.ToChar(acode) };
                                      byte\[\] b = enc.GetBytes(c);
                                      for (int i = 0; i < b.Length; i++)
                                      {
                                          output += String.Format("%{0:x2}", b\[i\]).ToUpper();
                                      }
                                      // Advance to pos after ;
                                      pos = pos2 + 1;
                                  }
                                  else
                                  {
                                      output += smain\[pos\];
                                      pos += 1;
                                  }
                              }
                              Console.WriteLine(output);
                           }
                      

                      modified on Wednesday, April 6, 2011 7:05 AM

                      N Offline
                      N Offline
                      Naveed727
                      wrote on last edited by
                      #10

                      Thank you very much davidnz you guys really help me out. Seriously I was stuck and you guys show me how to solve this problem.

                      L 1 Reply Last reply
                      0
                      • N Naveed727

                        Thank you very much davidnz you guys really help me out. Seriously I was stuck and you guys show me how to solve this problem.

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        You're welcome. I tidied mine up a bit this morning but have a feeling it could still be a lot simpler. I'm not much of a regex guru, but this is I think a lot tidier than my first attempt.

                            private static void TestReg2()
                            {
                                UTF8Encoding enc = new System.Text.UTF8Encoding();
                                string output = "";
                                string smain = "&amp;#1495;&amp;#1489;&amp;#1512;&amp;#1493;&amp;#1514;-&amp;#1514;&amp;#1497;&amp;#1497;&amp;#1512;&amp;#1493;&amp;#1514;";
                                int len = smain.Length;
                                int pos = 0;
                                uint acode = 0;
                                smain = Regex.Replace(smain,@"&amp;#\[0-9\]+;",(m) => {
                                    Match m2 = Regex.Match(m.Value, @"\[0-9\]+");
                                    if (m2.Length > 0)
                                    {
                                        acode = uint.Parse(m2.Value);
                                        output = "";
                                        char\[\] c = { Convert.ToChar(acode) };
                                        byte\[\] b = enc.GetBytes(c);
                                        for (int i = 0; i < b.Length; i++)
                                        {
                                            output += String.Format("%{0:x2}", b\[i\]).ToUpper();
                                        }
                                        return output;
                                    }
                                    else
                                        return "";
                                });
                                Console.WriteLine(smain);
                            }
                        
                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups