473,804 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

StreamReader mutilates '+'characters in UTF-7 files

Hi,

I need to process files that are created in UTF-7 format.
This works fine upto the point where a '+' character
(0x2B/43) appears in the line. The string is mutilated...

The reader appears to have a bug - or am I doing
something wrong here???
The code:
StreamReader Reader = new StreamReader
(@"MyLocalFile. txt", System.Text.Enc oding.UTF7);
string sLine;
while((sLine = Reader.ReadLine ()) != null)
{
// Process the line
}

The text:
#(6+sections)

Can anybody give me a clue to what is happening here?

Thanks, Hans
Nov 15 '05 #1
7 4804
Hans <an*******@disc ussions.microso ft.com> wrote:
I need to process files that are created in UTF-7 format.

This works fine upto the point where a '+' character
(0x2B/43) appears in the line. The string is mutilated...

The reader appears to have a bug - or am I doing
something wrong here???
The code:
StreamReader Reader = new StreamReader
(@"MyLocalFile. txt", System.Text.Enc oding.UTF7);
string sLine;
while((sLine = Reader.ReadLine ()) != null)
{
// Process the line
}

The text:
#(6+sections)

Can anybody give me a clue to what is happening here?


Are you absolutely sure it's UTF-7? In UTF-7, the "+" character
signifies a shift into a modified Base64 mode. See
http://www.faqs.org/rfcs/rfc2152.html for more details.

Where do you get this text file from? UTF-7 is not a very common
character encoding at all - UTF-8 is rather more likely.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Every older piece of windows software as well as the unix
world produce UTF-7 type files. And that's were the file
comes from.

Please explain why notepad/wordpad/visual studio/... CAN
display the contents of the file without a problem!

Regards,Hans
-----Original Message-----
Hans <an*******@disc ussions.microso ft.com> wrote:
I need to process files that are created in UTF-7 format.
This works fine upto the point where a '+' character
(0x2B/43) appears in the line. The string is mutilated...
The reader appears to have a bug - or am I doing
something wrong here???
The code:
StreamReader Reader = new StreamReader
(@"MyLocalFile. txt", System.Text.Enc oding.UTF7);
string sLine;
while((sLine = Reader.ReadLine ()) != null)
{
// Process the line
}

The text:
#(6+sections)

Can anybody give me a clue to what is happening here?
Are you absolutely sure it's UTF-7? In UTF-7, the "+"

charactersignifies a shift into a modified Base64 mode. See
http://www.faqs.org/rfcs/rfc2152.html for more details.

Where do you get this text file from? UTF-7 is not a very commoncharacter encoding at all - UTF-8 is rather more likely.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.

Nov 15 '05 #3
I just found out that
StreamReader Reader = new StreamReader
(@"MyLocalFile. txt", System.Text.Enc oding.Default);

produces the desired result.

One of my books, however, says that "using the Default
property is discouraged".

Can anybody tell me why???

Thanks, Hans
-----Original Message-----
Hi,

I need to process files that are created in UTF-7 format.
This works fine upto the point where a '+' character
(0x2B/43) appears in the line. The string is mutilated...

The reader appears to have a bug - or am I doing
something wrong here???
The code:
StreamReader Reader = new StreamReader
(@"MyLocalFile .txt", System.Text.Enc oding.UTF7);
string sLine;
while((sLine = Reader.ReadLine ()) != null)
{
// Process the line
}

The text:
#(6+sections )

Can anybody give me a clue to what is happening here?

Thanks, Hans
.

Nov 15 '05 #4
<an*******@disc ussions.microso ft.com> wrote:
I just found out that
StreamReader Reader = new StreamReader
(@"MyLocalFile. txt", System.Text.Enc oding.Default);

produces the desired result.
In which case, as I suspected, it *wasn't* UTF-7.
One of my books, however, says that "using the Default
property is discouraged".

Can anybody tell me why???


It means that only people with the same default will get the same
results - and the default will depend on things like operating system,
regional settings etc.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5
Hans <an*******@disc ussions.microso ft.com> wrote:
Every older piece of windows software as well as the unix
world produce UTF-7 type files. And that's were the file
comes from.

Please explain why notepad/wordpad/visual studio/... CAN
display the contents of the file without a problem!


I don't think UTF-7 means what you think it means. UTF-7 is a way of
encoding Unicode characters within ASCII files.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6
Sun an Notepad (at least by default) produce ANSI encoded
files. 'System.Text.En coding.Default' (like GetACP())
encodes according to...... the system's current ANSI code
page.

If there's another way to get ANSI-encoding do tell me!!!

Hans.

-----Original Message-----
<an*******@disc ussions.microso ft.com> wrote:
I just found out that
StreamReader Reader = new StreamReader
(@"MyLocalFile. txt", System.Text.Enc oding.Default);

produces the desired result.
In which case, as I suspected, it *wasn't* UTF-7.
One of my books, however, says that "using the Default
property is discouraged".

Can anybody tell me why???


It means that only people with the same default will get

the sameresults - and the default will depend on things like operating system,regional settings etc.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.

Nov 15 '05 #7
Hans <an*******@disc ussions.microso ft.com> wrote:
Sun an Notepad (at least by default) produce ANSI encoded
files.

'System.Text.En coding.Default' (like GetACP())
encodes according to...... the system's current ANSI code
page.

If there's another way to get ANSI-encoding do tell me!!!


It's a case of *which* ANSI-encoding to use though. If you always use
the default one for the computer, it means that if you transfer files
to/from another computer with a different default, you're in trouble.
If you let the user specify the encoding (using Encoding.Defaul t as the
default, but not relying on it) you give a lot more flexibility - and
if you also give the option of reading/writing in UTF-8, you end up
with the full flexibility of Unicode in a fairly compact form.

(Certainly if you don't need an older tool to understand the file
you're writing, I'd go with UTF-8 virtually every time.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #8

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

Similar topics

17
47826
by: Pikkel | last post by:
i'm looking for a way to replace special characters with characters without accents, cedilles, etc.
1
1917
by: Raed Sawalha | last post by:
I have a HTML file containing Hebrew and Arabic text when using following code to read its content string templateFile = Server.MapPath("MsgTemplate.htm"); System.IO.StreamReader reader = new System.IO.StreamReader(templateFile); string fileHTML = reader.ReadToEnd(); reader.Close(); the retured string is only the HTML without the arabic or Hebrew text ,WHY? (where the arabic and hebrew text are location is blank!!!!
2
381
by: Ian Oldbury | last post by:
I'm having a problem reading from a flat file, in the file "" and "" exist however when i view the contents of the variable LineContents these characters don't exist. Has anyone got any suggestions???? Dim LineContents as string Dim fs As FileStream
7
7774
by: Drew Berkemeyer | last post by:
Hello, I'm using the following code to read a text file in VB.NET. Dim sr As StreamReader = File.OpenText(strFilePath) Dim input As String = sr.ReadLine() While Not input Is Nothing strReturn += input + vbCrLf input = sr.Read
3
3800
by: pabelard | last post by:
I am reading from a file and trying to find out if it has characters above ASCII 127 in it. My sample file does have several of these characters. However, the streamreader seems to skip over them. Even if I read in lines and then write them out to another file, the high ASCII number characters disappear. My code:
2
16309
by: Bryan Dickerson | last post by:
StreamReader says it is designed to read a stream of characters StringReader says it is designed to read a string TextReader says it is designed to read a sequential list of characters. I hate to sound like a VB6 grump, but aren't we splitting hairs?? What's the difference? -- TFWBWY...A
11
31739
by: LucaJonny | last post by:
Hi, I've got a problem using StreamReader in VB.NET. I try to read a txt file that contains extended characters and theese are removed from the line that is being read. I've read a lot of articles about ANSI encoding like this http://support.microsoft.com/default.aspx?scid=kb;en-us;889835 but System.Text.Encoding.Default don't work!!
7
2154
by: sweetpotatop | last post by:
Hello, I have a txt file which has a few lines of special characters: This is A line from the text file: ٦-ŧُʍѥޘ²ů'ۣб'с ',,طꎏЏ׮ When I use sr.ReadLine (where "sr As StreamReader"), it is not giving me this line
4
34194
by: George | last post by:
Hi, I am puzzled by the following and seeking some assistance to help me understand what happened. I have very limited encoding knowledge. Our SAP system writes out a text file which includes German characters. 1. When I use StreamReader(System.String filepath) without specifying an encoding method, the German characters such as Ä are lost when I do a ReadLine()
0
2365
by: rajana | last post by:
Dear All, We have Ansi file with german characters ( / ) , We are using Streamreader to read the contents of the file. But Readline() not able to read the German characters. We tried all possibilities of calling the streamreader, but nothing worked. Dim sr As StreamReader = New StreamReader(Filename, System.Text.Encoding.Default, True) Dim sr As StreamReader = New StreamReader(Filename, _System.Text.Encoding.ASCII, False, 512)
0
9595
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
10354
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
10359
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
10101
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...
0
9177
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6870
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
5536
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...
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3005
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.