473,395 Members | 1,348 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,395 software developers and data experts.

End of Line Marker

KNE
I'm writing some code that is formating an output file being generated
within a web app. I want to allow the site administrator to configure the
characters that will mark the end of each line/record in the file.
Therefore, I added a key to my web.config appSettings section similar to the
following:

<add key="EORMarker" value="\r\n" />

This way, the setting can be changed to use "\r", "\n", "\n\r", "\r\n\n",
etc. I retrieve the appSetting value with code in the Global.asax and load
it into the application cache for quick access as in:

string eorMarker =
((NameValueCollection)ConfigurationSettings.GetCon fig("appSettings"))["EORMa
rker"];

Context.Cache.Insert("EORMarker", eorMarker, new
CacheDependency(Server.MapPath("web.config")));

I have a static lookup method I use to pull the string out of the cache when
needed:

public static string EORMarker()

{

return (string)HttpContext.Current.Cache["EORMarker"];

}

When I write a record/line to the output file, I tack on the characters
intended to serve as the End Of Record marker:

myStream.Write(this.myHeader + Lookup.EORMarker());

However, instead of getting an expected carriage return and line feed at the
end of the record/line, I literally get the "\r\n" characters in the output.
If I put the literal string in place of the lookup method:

myStream.Write(this.myHeader + "\r\n");

I get the desired / correct effect (a CR/LF to a new line). What can I do
to make pulling the End of Record Marker from the appSettings give me the
effect I want?

Thanks,

Ken


Nov 15 '05 #1
3 21322
The symbols \r and \n don't have any special meaning in XML like they do in
a C# string literal. To indicate these characters in XML you would use
and

"KNE" <Ke************@comcast.net> wrote in message
news:Os*************@TK2MSFTNGP12.phx.gbl...
I'm writing some code that is formating an output file being generated
within a web app. I want to allow the site administrator to configure the
characters that will mark the end of each line/record in the file.
Therefore, I added a key to my web.config appSettings section similar to the following:

<add key="EORMarker" value="\r\n" />

This way, the setting can be changed to use "\r", "\n", "\n\r", "\r\n\n",
etc. I retrieve the appSetting value with code in the Global.asax and load it into the application cache for quick access as in:

string eorMarker =
((NameValueCollection)ConfigurationSettings.GetCon fig("appSettings"))["EORMa rker"];

Context.Cache.Insert("EORMarker", eorMarker, new
CacheDependency(Server.MapPath("web.config")));

I have a static lookup method I use to pull the string out of the cache when needed:

public static string EORMarker()

{

return (string)HttpContext.Current.Cache["EORMarker"];

}

When I write a record/line to the output file, I tack on the characters
intended to serve as the End Of Record marker:

myStream.Write(this.myHeader + Lookup.EORMarker());

However, instead of getting an expected carriage return and line feed at the end of the record/line, I literally get the "\r\n" characters in the output. If I put the literal string in place of the lookup method:

myStream.Write(this.myHeader + "\r\n");

I get the desired / correct effect (a CR/LF to a new line). What can I do
to make pulling the End of Record Marker from the appSettings give me the
effect I want?

Thanks,

Ken


Nov 15 '05 #2

"Bret Mulvey" <br***@microsoft.nospam0000.com> wrote in message
news:PkQcb.580503$YN5.422164@sccrnsc01...
The symbols \r and \n don't have any special meaning in XML like they do in a C# string literal. To indicate these characters in XML you would use and
or you could simply modify EORMarker(why is that a method anyway?) to parse
and create acorrect string and store it locally, that allows end users a
much easier time writing different EOR markers, remembering the codes for
those would suck.

something like this would do it, but this is certainly not thread safe and
you'll have to do what you need to handle that(I recommend Jon Skeet's
article on the subject[1] for handling thread saftey and lazy init):

static string eorMarker=null;
public static string EORMarker {
get {
if (_eorMarker != null) {
eorMarker =
((NameValueCollection)ConfigurationSettings.GetCon fig("appSettings"))["EORMa
rker"];
eorMarker = eorMarker.Replace(@"\n", "\n");
eorMarker = eorMarker.Replace(@"\r","\r");

}
return eorMarker;
}
}

[1] http://www.pobox.com/~skeet/csharp/singleton.html "KNE" <Ke************@comcast.net> wrote in message
news:Os*************@TK2MSFTNGP12.phx.gbl...
I'm writing some code that is formating an output file being generated
within a web app. I want to allow the site administrator to configure the characters that will mark the end of each line/record in the file.
Therefore, I added a key to my web.config appSettings section similar to

the
following:

<add key="EORMarker" value="\r\n" />

This way, the setting can be changed to use "\r", "\n", "\n\r", "\r\n\n", etc. I retrieve the appSetting value with code in the Global.asax and

load
it into the application cache for quick access as in:

string eorMarker =

((NameValueCollection)ConfigurationSettings.GetCon fig("appSettings"))["EORMa
rker"];

Context.Cache.Insert("EORMarker", eorMarker, new
CacheDependency(Server.MapPath("web.config")));

I have a static lookup method I use to pull the string out of the cache

when
needed:

public static string EORMarker()

{

return (string)HttpContext.Current.Cache["EORMarker"];

}

When I write a record/line to the output file, I tack on the characters
intended to serve as the End Of Record marker:

myStream.Write(this.myHeader + Lookup.EORMarker());

However, instead of getting an expected carriage return and line feed at

the
end of the record/line, I literally get the "\r\n" characters in the

output.
If I put the literal string in place of the lookup method:

myStream.Write(this.myHeader + "\r\n");

I get the desired / correct effect (a CR/LF to a new line). What can I do to make pulling the End of Record Marker from the appSettings give me the effect I want?

Thanks,

Ken



Nov 15 '05 #3
Of course, I missed that you're using asp.net, in that case the parse code
is all you need then throw the new string into your cache, instead of
worrying about threadsafe singleton initialization.

"Daniel O'Connell" <onyxkirx@--NOSPAM--comcast.net> wrote in message
news:iiRcb.433313$cF.137782@rwcrnsc53...

"Bret Mulvey" <br***@microsoft.nospam0000.com> wrote in message
news:PkQcb.580503$YN5.422164@sccrnsc01...
The symbols \r and \n don't have any special meaning in XML like they do in
a C# string literal. To indicate these characters in XML you would use

and

or you could simply modify EORMarker(why is that a method anyway?) to

parse and create acorrect string and store it locally, that allows end users a
much easier time writing different EOR markers, remembering the codes for
those would suck.

something like this would do it, but this is certainly not thread safe and
you'll have to do what you need to handle that(I recommend Jon Skeet's
article on the subject[1] for handling thread saftey and lazy init):

static string eorMarker=null;
public static string EORMarker {
get {
if (_eorMarker != null) {
eorMarker =
((NameValueCollection)ConfigurationSettings.GetCon fig("appSettings"))["EORMa rker"];
eorMarker = eorMarker.Replace(@"\n", "\n");
eorMarker = eorMarker.Replace(@"\r","\r");

}
return eorMarker;
}
}

[1] http://www.pobox.com/~skeet/csharp/singleton.html
"KNE" <Ke************@comcast.net> wrote in message
news:Os*************@TK2MSFTNGP12.phx.gbl...
I'm writing some code that is formating an output file being generated
within a web app. I want to allow the site administrator to configure the characters that will mark the end of each line/record in the file.
Therefore, I added a key to my web.config appSettings section similar to
the
following:

<add key="EORMarker" value="\r\n" />

This way, the setting can be changed to use "\r", "\n", "\n\r", "\r\n\n", etc. I retrieve the appSetting value with code in the Global.asax and load
it into the application cache for quick access as in:

string eorMarker =

((NameValueCollection)ConfigurationSettings.GetCon fig("appSettings"))["EORMa rker"];

Context.Cache.Insert("EORMarker", eorMarker, new
CacheDependency(Server.MapPath("web.config")));

I have a static lookup method I use to pull the string out of the cache
when
needed:

public static string EORMarker()

{

return (string)HttpContext.Current.Cache["EORMarker"];

}

When I write a record/line to the output file, I tack on the
characters intended to serve as the End Of Record marker:

myStream.Write(this.myHeader + Lookup.EORMarker());

However, instead of getting an expected carriage return and line feed
at the
end of the record/line, I literally get the "\r\n" characters in the

output.
If I put the literal string in place of the lookup method:

myStream.Write(this.myHeader + "\r\n");

I get the desired / correct effect (a CR/LF to a new line). What can

I do to make pulling the End of Record Marker from the appSettings give me the effect I want?

Thanks,

Ken




Nov 15 '05 #4

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

Similar topics

25
by: Haines Brown | last post by:
I have a table with three columns, and I want the data in the first column to align left, while that in the remaining columns to align right: #testTable { text-align: right; } #leftcol {...
2
by: jcb | last post by:
The following code in Python 2.3 f = file('t.txt', 'wt') f.write('\n') f.close() writes 0D0A to the file. Is this a bug or expected behavior? It sure took me by surprise.
9
by: DarkBlue | last post by:
Hello I need some help I have a text file which changes dynamically and has 200-1800 lines. I need to replace a line , this line can be located via a text marker like : somelines # THIS...
6
by: KraftDiner | last post by:
If you don't know how long your input data is going to be how can you at least treat it a text line at a time... like looking for new line in the data... Right now recv blocks. Yes I could do a...
2
by: Enrico Sabbadin | last post by:
Hi, A few days go I fiund iut that the xmlserializer strips away /r/n out during deserialization (and just leave /n) ... I found out that you can resolve this problem using the deserialize...
16
by: mazwolfe | last post by:
Someone recently asked about reading lines. I had this code written some time ago (part of a BASIC-style interpreter based on H. Shildts in Art of C) to read a file with the lines ended in any...
8
by: Wayne | last post by:
When I couldn't find it on-line by Googling, I spent all last night working it out. And it works, Yea! All you do is mark the PRE sections you want numbered with a "marker" style like this: ...
21
by: Timothy Madden | last post by:
Hello The examples in the php cli chapter in the manual end a line with "\n". For example echo "Total {$total}.\n"; Should it not be "\n" on Linux\Unix systems and "\r\n" on Windows systems ?...
2
by: flymo | last post by:
Hello All, Hopefully this is the correct forum... I have some code that creates a text (dat) for a billing process created in Access2000, I add an Eof of Line marker to each line item and then...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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.