473,804 Members | 3,548 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Positio n = 0;
long i = aStream.Length;
byte[] buffer = new byte[i];

aStream.Read(bu ffer,0,(int)aSt ream.Length);
return BytesToUTF8Stri ng(buffer);
}

public static string BytesToUTF8Stri ng(byte[] Array)
{
Encoding utf8 = Encoding.UTF8;
char[] utf8Chars = new char[utf8.GetCharCou nt(Array, 0,Array.Length)];
utf8.GetChars(A rray, 0, Array.Length, utf8Chars, 0);

return new string(utf8Char s);
}

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 2635
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.c om...
| 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.Positio n = 0;
| long i = aStream.Length;
| byte[] buffer = new byte[i];
|
| aStream.Read(bu ffer,0,(int)aSt ream.Length);
| return BytesToUTF8Stri ng(buffer);
| }
|
| public static string BytesToUTF8Stri ng(byte[] Array)
| {
| Encoding utf8 = Encoding.UTF8;
| char[] utf8Chars = new char[utf8.GetCharCou nt(Array, 0,Array.Length)];
| utf8.GetChars(A rray, 0, Array.Length, utf8Chars, 0);
|
| return new string(utf8Char s);
| }
|
| 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.language s.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
49369
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 Java VM is different from the OpenCms encoding! Java VM file encoding: UTF-8
8
2817
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 object, it is encoded in utf-8 automatically. It can be a problem when I'm building an interactive environment using "compile", with a different encoding from utf-8. IDLE itself has the same problem. ( '<a string with non-ascii-encoding>' is...
7
4976
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 windows-1252 and that it is not equivalent to iso-8859-1. Looking in the registry under HKEY_CLASSES_ROOT\MIME\Database\Charset and \Codepage, it seems that all variations on iso-8859-1 (latin1, etc) are mapped to code page 1252, which I'm...
8
2496
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 I'm identifying the encoding type. Here is the problem, some type of UTF-8 encoded file does'nt have BOM in the starting. So I'm identying the file as iso-8859-1 encoded which is actually encoded in UTF-8. I dont have much idea about the...
8
607
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 resulting xml ends up with the following declaration: <?xml version="1.0" encoding="utf-16"?> changing the encoding to utf-16, is there something I'm doing wrong? Is it
4
8852
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 version="1.0" encoding="utf-8" ?>... - ... I am using the WebRequest functionality to get the feeds. So, my code
5
3514
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 (where "MyWebSvcName" is the name of my web service). I don't know how to assign value to this parameter. (I'm using VB.NET 2003.) Here are some sample codes:
0
3635
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 value (which varies depending on the data being written), characters not available in the encoding specified in the Encoding property of the XmlWritterSettings instance used to create the XmlWriter are being written to the resulting XML document as...
3
2493
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 typed dataset tableadaptor). In that case, I have a problem: what encoding do I use to conver the byte (or memorystream) into a string? The encoding is in the file, of course, like any XML file, but how do I find out which? I tried using an...
23
5034
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 from another HTML page viewed in IE7, that is also UTF-8 encoded (search for "china" on google.com). I paste the chineese chars into a content editable div. My Ajax webservice compiles an XML where the data from the content editable div is...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10326
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10317
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.