Problem to convert my code and don't know how to search for it over google
-
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 -
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 advanceI'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("חברות-תיירות"))</p>
-
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("חברות-תיירות"))</p>
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/&#1495;&#1489;&#1512;&#1493;&#1514;-&#1514;&#1497;&#1497;&#1512;&#1493;&#1514;/](http://easy.co.il/&#1495;&#1489;&#1512;&#1493;&#1514;-&#1514;&#1497;&#1497;&#1512;&#1493;&#1514;/)[[^](http://easy.co.il/&#1495;&#1489;&#1512;&#1493;&#1514;-&#1514;&#1497;&#1497;&#1512;&#1493;&#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. -
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.
&#1495;&#1489;&#1512;&#1493;&#1514;-&#1514;&#1497;&#1497;&#1512;&#1493;&#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 -
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.
&#1495;&#1489;&#1512;&#1493;&#1514;-&#1514;&#1497;&#1497;&#1512;&#1493;&#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 advanceHi, 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.
-
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.
&#1495;&#1489;&#1512;&#1493;&#1514;-&#1514;&#1497;&#1497;&#1512;&#1493;&#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 advanceand 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
-
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
-
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.
-
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.
&#1495;&#1489;&#1512;&#1493;&#1514;-&#1514;&#1497;&#1497;&#1512;&#1493;&#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 advanceA bit ugly, but seems to work...
private static void TestDecode() { UTF8Encoding enc = new System.Text.UTF8Encoding(); string output = ""; string smain = "&#1495;&#1489;&#1512;&#1493;&#1514;-&#1514;&#1497;&#1497;&#1512;&#1493;&#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) == "&#") { // 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
-
A bit ugly, but seems to work...
private static void TestDecode() { UTF8Encoding enc = new System.Text.UTF8Encoding(); string output = ""; string smain = "&#1495;&#1489;&#1512;&#1493;&#1514;-&#1514;&#1497;&#1497;&#1512;&#1493;&#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) == "&#") { // 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
-
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.
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 = "&#1495;&#1489;&#1512;&#1493;&#1514;-&#1514;&#1497;&#1497;&#1512;&#1493;&#1514;"; int len = smain.Length; int pos = 0; uint acode = 0; smain = Regex.Replace(smain,@"&#\[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); }