473,471 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Reading \r From File As Carriage Return

I have an xml file that is read into an object using serialization. One
of the objects has a string field called delimeter that I want to
contain a carriage return. Instead of trying to include the carriage
return, I used "\r" thinking that when it was read back into the object
it would be interpreted as a carriage return. Instead, I am getting the
string literal instead of the escape sequence. Does anybody have a
slick way of telling it to return a carriage return? I'd rather not
have to use special cases for escape characters, but I will if
necessary.

Cheers!
Russ

Jun 13 '06 #1
3 3360
For expediency sake, I have implemented the following code:

private char[] ReturnDelimiter(string strDelimiter)
{
char[] achrDelimiter;
switch(strDelimiter)
{
case "\r":
achrDelimiter = new char[]{'\r'};
break;
case "\n":
achrDelimiter = new char[]{'\n'};
break;
case "\r\n":
achrDelimiter = new char[]{'\r','\n'};
break;
case "\t":
achrDelimiter = new char[]{'\t'};
break;
default:
achrDelimiter = strDelimiter.ToCharArray();
break;
}

return achrDelimiter;
}

But I'd still like to know if there is a better way to do this.
Especially if it can be read in as an escape sequence from the file
during serialization.

Cheers
Russ

Dinsdale wrote:
I have an xml file that is read into an object using serialization. One
of the objects has a string field called delimeter that I want to
contain a carriage return. Instead of trying to include the carriage
return, I used "\r" thinking that when it was read back into the object
it would be interpreted as a carriage return. Instead, I am getting the
string literal instead of the escape sequence. Does anybody have a
slick way of telling it to return a carriage return? I'd rather not
have to use special cases for escape characters, but I will if
necessary.

Cheers!
Russ


Jun 13 '06 #2
Dinsdale,

Before you de-serialize the object, couldn't you read the file into a
string, do a String.Replace() and convert the \r's to carriage returns,
then dump it into a stream to be read by the xml deserialize?

Is the file a binary object or text-readable?

<?
TextReader r = new StreamReader( "something.xml" );
string datastr=r.ReadToEnd();
datastr.Replace("\\r","\r");
StringReader str = new StringReader(datastr);
newList = (ShoppingList)s.Deserialize( str );
?>

You might want to double check that cause I did it from memory, but it
should work.
Michael Brown
360 Replays Ltd.

Jun 14 '06 #3
Great suggestion Mike, thanks. It never ceases to amaze me what other
people can see that I miss. :)

Russ

MIke Brown wrote:
Dinsdale,

Before you de-serialize the object, couldn't you read the file into a
string, do a String.Replace() and convert the \r's to carriage returns,
then dump it into a stream to be read by the xml deserialize?

Is the file a binary object or text-readable?

<?
TextReader r = new StreamReader( "something.xml" );
string datastr=r.ReadToEnd();
datastr.Replace("\\r","\r");
StringReader str = new StringReader(datastr);
newList = (ShoppingList)s.Deserialize( str );
?>

You might want to double check that cause I did it from memory, but it
should work.
Michael Brown
360 Replays Ltd.


Jun 14 '06 #4

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

Similar topics

17
by: Guyon Morée | last post by:
what is the difference? if I open a text file in binary (rb) mode, it doesn't matter... the read() output is the same.
2
by: christos panagiotou | last post by:
hi all I am trying to open some .raw files that represent images (256x256, 8 bit per pixel, no header) in a c++ program I cannot copy paste the module here as it uses a method from the VTK...
14
by: Job Lot | last post by:
I have tab delimited text file which gets populated on daily basis via automated process. New entry is written at the bottom. I need to create a utility which makes a copy of this file with 10 most...
5
by: stephane | last post by:
Hi, I don't know how to test something. I read at file.txt caracter by caracter And I would like to know when it is the end of my line in the text file. exemple of a line: ...
11
by: Michael McGarry | last post by:
Hi, I am reading strings from a text file using fscanf("%s", currToken); This returns strings delimited by whitespace. How can I tell if the string was followed by a carriage return in the...
13
by: ACC | last post by:
Hi! I'm developing an application to analyze some information that is inside a text file. The size of the text file goes from 50Mb to 220Mb... The text file is like a table, with "rows" and...
11
by: Someone | last post by:
Hello Using the c file io functions if reading a csv file there is a problem if a field contains an embedded carriage return. So I can check for apostrophe pairs but processing does seem a bit...
1
by: RishiD | last post by:
Hi, Trying to read an input file, of characters with spaces and carriage returns. Basically it is a 20x20 matrix of characters with spaces. I want to load the information into an two...
4
by: C++ Newbie | last post by:
Suppose I have a text file with the input: 1 2 3 4 5 6 7 8 9 10 ! Comment: Integers 1 - 10 How do I write a C++ program that reads in this line into a 10-element vector and ignores the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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 project—planning, coding, testing,...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.