473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

encoding problem

Hi,

..net c# httphandler straight html form at browser.

GBP pound sign problem (I know I know - I *can* decode it, but I've got to
understand what and why I should be doing stuff)

I am uploading text data from a form. This data is either directly input into a
textarea, or is a file stream originating from a .txt file, (or other basic text
file (like off Mac or Unix - of course I don't necessarily know at present it's
only .txt)

The page encoding is :-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

On arrival at the server the content encoding is, sure enough UTF8.

Data input via the textarea and input to a string is displayed in the debugger
as pounds (£)

Data input as a filestream has in the stream single bytes containing 0xA3 for
the GBP pound sign.

I process the input stream like this :-

public static string StreamToString(Stream aStream)
{ {
aStream.Position = 0;
long i = aStream.Length;
byte[] buffer = new byte[i];

aStream.Read(buffer,0,(int)aStream.Length);
return BytesToUTF8String(buffer);
}

public static string BytesToUTF8String(byte[] Array)
{
Encoding utf8 = Encoding.UTF8;
char[] utf8Chars = new char[utf8.GetCharCount(Array, 0,Array.Length)];
utf8.GetChars(Array, 0, Array.Length, utf8Chars, 0);

return new string(utf8Chars);
}

The resulting string contains nothing ...

If I use ASCII instead of UTF8, I get sense except my GBP signs are query ?
marks.

If I use UTF7 I get an apparently OK decoding.

I am dubious about using UTF7 for no better reason than that it works. Is there
logic here? What should I be doing?

Thanks,
Jim
Nov 19 '05 #1
2 2609
it doesn't really matter what encoding you use for the page response, whats
important is the encoding used on the post from the browser. the browser
picks this (though often it will match). you should check the content-type
header the browser sends to determine the character set. for a html form
post (application/x-www-form-urlencoded) IS0-8859-1 is the default character
set not utf8.

-- bruce (sqlwork.com)
"Jim Lawton" <uc**@use.your.initiative> wrote in message
news:84********************************@4ax.com...
| Hi,
|
| .net c# httphandler straight html form at browser.
|
| GBP pound sign problem (I know I know - I *can* decode it, but I've got to
| understand what and why I should be doing stuff)
|
| I am uploading text data from a form. This data is either directly input
into a
| textarea, or is a file stream originating from a .txt file, (or other
basic text
| file (like off Mac or Unix - of course I don't necessarily know at present
it's
| only .txt)
|
| The page encoding is :-
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
| On arrival at the server the content encoding is, sure enough UTF8.
|
| Data input via the textarea and input to a string is displayed in the
debugger
| as pounds (£)
|
| Data input as a filestream has in the stream single bytes containing 0xA3
for
| the GBP pound sign.
|
| I process the input stream like this :-
|
| public static string StreamToString(Stream aStream)
| { {
| aStream.Position = 0;
| long i = aStream.Length;
| byte[] buffer = new byte[i];
|
| aStream.Read(buffer,0,(int)aStream.Length);
| return BytesToUTF8String(buffer);
| }
|
| public static string BytesToUTF8String(byte[] Array)
| {
| Encoding utf8 = Encoding.UTF8;
| char[] utf8Chars = new char[utf8.GetCharCount(Array, 0,Array.Length)];
| utf8.GetChars(Array, 0, Array.Length, utf8Chars, 0);
|
| return new string(utf8Chars);
| }
|
| The resulting string contains nothing ...
|
| If I use ASCII instead of UTF8, I get sense except my GBP signs are query
?
| marks.
|
| If I use UTF7 I get an apparently OK decoding.
|
| I am dubious about using UTF7 for no better reason than that it works. Is
there
| logic here? What should I be doing?
|
| Thanks,
| Jim
Nov 19 '05 #2
On Tue, 11 Jan 2005 10:03:03 -0800, "bruce barker" <no***********@safeco.com>
wrote:
it doesn't really matter what encoding you use for the page response, whats
important is the encoding used on the post from the browser. the browser
picks this (though often it will match). you should check the content-type
header the browser sends to determine the character set. for a html form
post (application/x-www-form-urlencoded) IS0-8859-1 is the default character
set not utf8.

-- bruce (sqlwork.com)


Thanks Bruce,

for anyone googling this topic in future, there's more in
dotnet.languages.csharp
Message-ID: <36********************************@4ax.com>

cheers Jim
Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ann | last post by:
Hi, Is there any way to Change encoding of Java Vm to ISO-8859-1? i am using Java vm along with an application called opencms. I get the following error message.. Error: the encoding of your...
8
by: janeaustine50 | last post by:
Python's InteractiveInterpreter uses the built-in compile function. According to the ref. manual, it doesn't seem to concern about the encoding of the source string. When I hand in an unicode...
7
by: Mark | last post by:
Hi... I've been doing a lot of work both creating and consuming web services, and I notice there seems to be a discontinuity between a number of the different cogs in the wheel centering around...
8
by: davisjoseph | last post by:
Hi All, I'm newbie to this XML world. My problem is to identify the encoding type of XML at runtime. What currently I'm doing is checking whether BOM is available in the XML; based on the BOM...
8
by: Demon News | last post by:
I'm trying to do a transform (Using XmlTransform class in c#) and in the Transform I'm specifying the the output xsl below: <xsl:output method="xml" encoding="UTF-8" indent="no"/> the...
4
by: fitsch | last post by:
Hi, I am trying to write a generic RSS/Atom/OPML feed client. The problem is, that those xml feeds may have different encodings: - <?xml version="1.0" encoding="ISO-8859-1" ?>... - <?xml...
5
by: James Wong | last post by:
Dear all, I've a web service function and it contains a parameter in System.Text.Encoding. I found that the data type of this parameter in caller application becomes MyWebSvcName.Encoding...
0
by: Janusz Nykiel | last post by:
I've stumbled upon unexpected behavior of the .NET 2.0 System.Xml.XmlWriter class when using it to write data to a binary stream (System.IO.Stream). If the amount of data is less than a certain...
3
by: Martin Z | last post by:
Hi, I have an application that involves sending a lot of XML data to various places. The problem is that once in a while, I just want the XML document as a string (for example, sending to a...
23
by: Allan Ebdrup | last post by:
I hava an ajax web application where i hvae problems with UTF-8 encoding oc chineese chars. My Ajax webapplication runs in a HTML page that is UTF-8 Encoded. I copy and paste some chineese chars...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.