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 3 3379
For expediency sake, I have implemented the following code:
private char[] ReturnDelimiter (string strDelimiter)
{
char[] achrDelimiter;
switch(strDelim iter)
{
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.To CharArray();
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
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.ReadT oEnd();
datastr.Replace ("\\r","\r") ;
StringReader str = new StringReader(da tastr);
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.
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.ReadT oEnd(); datastr.Replace ("\\r","\r") ; StringReader str = new StringReader(da tastr); 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
|
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
(Visualization Toolkit)
the module i ve got is already tested with the same dataset and it works
if these files have been created under windows and copied in linux (i am
|
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 recent entries.
When I read line using StreamReader object it starts from the top, so
looping though lines and keeping track of the line is not helpful. Is there
anyway to start reading from the bottom or if anyone could suggest some other...
|
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:
stephane;vollet;1234;
|
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 file?
Michael
| |
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 "columns", and several
"cells" represent an objects in my application.
What I need to do is, read the text file line by line, parse the
|
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 of a struggle. Has anyone got a robust
algorithm or functions to use to reliably get a whole row of text from a csv
file even if some fields contain embedded carriage returns?
Angus
|
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 dimensional array.
Cannot seem to figure out how to do like if the read character equals a
space or carriage return, don't put it in the array.
Any ideas?
|
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 comment?
Thanks.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |