Hi there I was wondering if anyone can help with this. I am submitting values to an access database using ASP classic and need to convert French characters to ASCII. I have done it before with an form to email script. here is the code that I used with the first line being the code that writes a value to the database field. any help would be great.
[code]
'--------------------------------------------------------------------------
' Checks form fields and headings for French Characters and replaces them
' with the ASCII equivalent.
'--------------------------------------------------------------------------
rsAddComments.Fields("Customer") = Request.Form("Customer")
body = Replace(body,"À",chr(192))
body = Replace(body,"Á",chr(193))
body = Replace(body,"Â",chr(194))
body = Replace(body,"Î",chr(206))
[/code]
Try to just put the ISO Latin 1 character set on the page:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
This work for me.
Actually that will not work. It is the way that access reads to text, same as outlook. I had to convert to ascii for outlook. What I did for that was
body = Replace(body,"é",chr(999))
Now I need to replace all of the values from the form fields with the ascii using ASP before it writes to the database. What I don't know is what to put in place of BODY in the above code.
Related
I have this in my querystring - sug_zehut=ז
(ז is a Hebrew letter)
Although I'm well aware that this is bad practice, I have to receive it like so in my query string (not my code..)
When I write it to a hidden I get sug_zehut=%EF%BF%BD as a part of the querystring, and when I try to put it in a string and put that in a hidden, I get � (I found here that those two are the same).
Anyhow, the question is - How do I get the value ז to my variable?
(I'm using .net version 4)
Thanks.
%EF%BF%BD is the code of � sumbol. That's mean your server don't know this character because of you sent symbol in one encoding and try get it as UTF-8.
Try to set up utf-8 encoding in every place (at least for testing of the problem):
In web.config
http://msdn.microsoft.com/en-us/library/ydkak5b9(v=vs.71).aspx
In the page
<meta charset="utf-8"> vs <meta http-equiv="Content-Type">
Change real file encoding if you directly set up your symbol (.cs,
.cshtml, .aspx, .js, ...)
If it's not working that please tell me how do you get this url and navigate on it?
Here's a small function to convert your character to an HTML encoded version (ז in this case). HtmlEncode won't do it for you in most versions of .net, unfortunately.
private static string UnicodeConvertChar(char input)
{
if (input > 159)
{
return "&#" + ((int)input).ToString() + ";";
}
else
{
return input.ToString();
}
}
You can convert it before setting it in your hidden field, and then when you get it back, you can simply read it by using HttpUtility.HtmlDecode.
Here's a dotnetfiddle for you to play around with it:
https://dotnetfiddle.net/jbDY0V
I am binding to a DropDownList as follows;
Sub bindGalleries(ByVal catID As Integer)
ddlGalleries.DataSource = Galleries.GetGalleries(catID)
ddlGalleries.DataTextField = "GalleryName"
ddlGalleries.DataValueField = "GalleryID"
ddlGalleries.DataBind()
End Sub
One of the items in the list is: 'Kültür & Sanat', which is displayed just right in the dropdownlist. But when I look at the source of the page, it is: Kültür & Sanat
How can I get the source to be exactly the same as the original string?
Note: my meta tag is: in master page..
This should give you what you need:
Server.HtmlDecode("Kültür & Sanat");
Write a method to "sanitize" the items in the DDL and store them in an array. Then just bind to the array.
You can populate the DDL in a similar fashion.
You may be able to use backslashes to escape
Try to put the proper charset in the heading portion of your page.
Example:
<meta http-equiv="Content-Type" content="text/html; charset=utf-16"/>
The reason why you see those characters is because those characters are being htmlencoded upon saving into your source.
i.e.
YourSource = server.htmlEncode(value)
or
YourSource = server.urlEncode
You can save it to its original form by using server.htmlDecode or by omitting the server.htmlEncode.
I am seeing a special character in the ASP .NET page I am rendering.
This page reads that content as XML Response from a REST service.
If I load the XML in browser, it displays "-" fine. (It's longer than the usual dash :))
But when print on the ASPX page repeater using EVAL, it displays a special character.
The page has a meta tag.
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
Though, the browser detects the page encoding as UTF-8.
I am looking for a solution so that I can get rid of special character.
The char is probably ASCII code 150 or 151. Some programs (notably MS-Word) use these for dash and long dash. The problem is that charset ISO-8859-1 does not map characters between 128 -159 to any value, so you cannot be sure how the browser will display the character.
The following function (just typed in, not checked) will convert your source string from 8859-1 to UTF-8
function string MakeUTF8String(string SourceStr)
{
byte[] b = Encoding.GetEncoding("iso-8859-1").GetBytes(SourceStr)
return System.Text.Encoding.UTF8.GetString(b);
}
I am sending an arabic value in a querystring, when retrieving it on the server, the value is erroneous and is replaced by quotation marks (????).
for example:
http://server/mypage.aspx?qs=مرحبا
the value of Request.QueryString("qs") is ?????
Note that Response.Write('مرحبا') executes correctly.
Any idea about this querystring problem?
Thanks.
Just URL Encode the arabic string and it should work fine.
Edit: You must URL Encode the string before putting it in the querystring.
For instance, if you were to url encode the space character, it will appear as %20 in your querystring, like this:
http://foo.com/dosomething?param1=hello%20world
Then when you read param1 you URL Decode it, and you get the string "hello world"
You could also URL Encode every single character but for regular characters it's pointless.
I sent an Arabic text in my query string
and when I resieved this string it was Encoded
after Server.UrlDecode
departmentName = Server.UrlDecode(departmentName);
it back again to arabic
so just use Server.UrlDecode(encodedString);
Hope this help you
I had a similar problem and solved it by putting the following line in my web.config file:
<globalization fileEncoding="windows-1256"
requestEncoding="windows-1256" responseEncoding="windows-1256"/>"
And this in the head section of my HTML page:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
The Non english characters can't be passed without being encoded ,
so you need to encode the value before you redirect to the target page as follows:
string text="مرحبا";
text=Server.UrlEncode(text);
string url="http://server/mypage.aspx?qs="+text;
Response.Redirect(url);
Using FreeTextBox, I'm capturing HTML-formatted text. The purpose is to allow a website owner to update their web page content on a few pages. I have the system completed except for knowing what to do with the resultant HTML markup.
After the page editor completes their work, I can get the output from FreeTextBox, in html format, like so: <font color="#000080"><b>This is some text.</b></font>
I tried storing it as escaped markup in web.config, but that didn't work since it kept hosing the tags even after I changed them to escaped characters, like so: <font color="#000080">
The reason I wanted to store this kind of string as a key in web.config is that I could successfully store a static string, set a lebel's value to it, and successfully render the text. But when I try to escape it, it gets reformatted in web.config by .Net somehow.
So I escaped all the characters, encoded them as Base64 and stored that. Then on page_load, I tried to decode it, but it just shows up as text, with all the html tags showing as well - it doesn't get rendered. I know a million people use this control, but I'm damned if I can figure out how to do it right.
So here's my question: how can I inject the saved HTML into an edited page so it shows up in browsers like the editor wants it to look?
Try Server.HtmlDecode to output the HTML to the screen.
As a side note, I prefer to use CKEditor for html-formatted input. I found it is the better option among all options (FreeTextBox, TinyMCE, anything else?) and it has got completely rewritten and faster in the version 3.0!
In case anyone comes here for the answer, here's one way to do it.
I had initial problems with web.config changing some of the HTML tags upon storage, so we use B64 encoding (may not be necessary). Store the saved html markup to an AppSettings key in web.config as Base64 encoding, using this for your setting update function. Add error checking and whatever else you need it to do:
'create configuration object
Dim cfg As Configuration
cfg = WebConfigurationManager.OpenWebConfiguration("~")
'get reference to appsettings("HTMLstring")
Dim HTMLString As KeyValueConfigurationElement = _
CType(cfg.AppSettings.Settings("HTMLstring"), KeyValueConfigurationElement)
'get text entered by user and marked up with HTML tags from FTB1, then
'encode as Base64 so we can store it as XML-safe string in web.config
Dim b64String As String = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(FTB1.Text))
'save new value into web.config
If Not HTMLString Is Nothing Then
HTMLString.Value = b64String
cfg.Save()
End If
Next, add a Literal control to the aspx markup:
<asp:Literal id="charHTML" runat="server"/>
To add the saved HTML to the post-edited page, do the following in Page_Load:
'this string of HTML code is stored in web.config as Base64 to preserve XML-unsafe characters that come from FreeTextBox.
Dim injectedHTML As String = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(AppSettings("HTMLstring")))
'the literal control will directly inject this HTML instead of encoding it
charHTML.Mode = LiteralMode.PassThrough
'set the value
charHTML.Text = injectedHTML
Hope this helps. sF