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

Convert UNIX Line Breaks

Hi,

I am new to C# and I am facing this small problem:

I start a new process using cygwin and I redirect the standard output
to a string variable. When I display the string variable in a list box
I see those squares representing UNIX line breaks. How can I convert
those to Windows style line breaks?

Thanks. Dave.
Nov 16 '05 #1
7 19882

My UNIX and my StringBuilder are really rusty but I think your line breaks are line feed chars - yes? A simple case approach {not nested quote aware etc...} is to replace all occurrences of LF characters with the .NET constant Environment.NewLine... My syntax isn't exact here but something like:

StringBuilder fixed = old;
fixed.Replace(LF, Environment.NewLine);
fixed.ToString();
.....

--Richard

"David Meier" wrote:
Hi,

I am new to C# and I am facing this small problem:

I start a new process using cygwin and I redirect the standard output
to a string variable. When I display the string variable in a list box
I see those squares representing UNIX line breaks. How can I convert
those to Windows style line breaks?

Thanks. Dave.

Nov 16 '05 #2
Write them to a temp file and run them through unix2dos or a similar tool
(or just feed the tool from STDIN).

Sure beats writing your own conversion code.
--
Klaus H. Probst, MVP
http://www.vbbox.com/
"David Meier" <de*@eth0.ch> wrote in message
news:84**************************@posting.google.c om...
Hi,

I am new to C# and I am facing this small problem:

I start a new process using cygwin and I redirect the standard output
to a string variable. When I display the string variable in a list box
I see those squares representing UNIX line breaks. How can I convert
those to Windows style line breaks?

Thanks. Dave.

Nov 16 '05 #3
Actually UNIX text files contain just "\n" (LF) at the end of the line,
while MS OS'es use "\r\n" (CR+LF)

Robert
"Richard" <Ri*****@discussions.microsoft.com> wrote in message
news:8C**********************************@microsof t.com...

My UNIX and my StringBuilder are really rusty but I think your line breaks are line feed chars - yes? A simple case approach {not nested quote aware
etc...} is to replace all occurrences of LF characters with the .NET
constant Environment.NewLine... My syntax isn't exact here but something
like:
StringBuilder fixed = old;
fixed.Replace(LF, Environment.NewLine);
fixed.ToString();
....

--Richard

"David Meier" wrote:
Hi,

I am new to C# and I am facing this small problem:

I start a new process using cygwin and I redirect the standard output
to a string variable. When I display the string variable in a list box
I see those squares representing UNIX line breaks. How can I convert
those to Windows style line breaks?

Thanks. Dave.

Nov 16 '05 #4
Yap. This did the trick:

StringBuilder fixed = old;
fixed.Replace("\n", Environment.NewLine);
fixed.ToString();

Thanks.

"Robert Misiak" <rm*****@users.cutthispartout.sourceforge.net> wrote in message news:<jG******************@newsread1.news.pas.eart hlink.net>...
Actually UNIX text files contain just "\n" (LF) at the end of the line,
while MS OS'es use "\r\n" (CR+LF)

Robert
"Richard" <Ri*****@discussions.microsoft.com> wrote in message
news:8C**********************************@microsof t.com...

My UNIX and my StringBuilder are really rusty but I think your line breaks

are line feed chars - yes? A simple case approach {not nested quote aware
etc...} is to replace all occurrences of LF characters with the .NET
constant Environment.NewLine... My syntax isn't exact here but something
like:

StringBuilder fixed = old;
fixed.Replace(LF, Environment.NewLine);
fixed.ToString();
....

--Richard

"David Meier" wrote:
Hi,

I am new to C# and I am facing this small problem:

I start a new process using cygwin and I redirect the standard output
to a string variable. When I display the string variable in a list box
I see those squares representing UNIX line breaks. How can I convert
those to Windows style line breaks?

Thanks. Dave.

Nov 16 '05 #5
Klaus H. Probst <us*******@vbbox.com> wrote:
Write them to a temp file and run them through unix2dos or a similar tool
(or just feed the tool from STDIN).

Sure beats writing your own conversion code.


I think the code required to run the conversion tool is likely to be
considerably longer than calling String.Replace, to be honest.

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

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote
Sure beats writing your own conversion code.


I think the code required to run the conversion tool is likely to be
considerably longer than calling String.Replace, to be honest.


Well true, but what if the file is huge =)

--
klaus
Nov 16 '05 #7
Klaus H. Probst <us*******@vbbox.com> wrote:
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote
Sure beats writing your own conversion code.


I think the code required to run the conversion tool is likely to be
considerably longer than calling String.Replace, to be honest.


Well true, but what if the file is huge =)


Then do it line by line with StreamReader - in fact, as StreamReader
accepts any kind of line break, if you're happy to process a line at a
time you don't need to do anything. Otherwise, just have one
StreamReader, and one StreamWriter to write out the file with the right
line breaks, and you'll still end up with less code than setting up the
process etc, I suspect. (It'll also reduce the dependency on an extra
tool.)

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

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

Similar topics

1
by: Bill | last post by:
I am downloading data from a website that displays it in a table $fp = fopen("a website page", 'r'); The following accesses the stream one <td> element at a time $myData = fgets($fp); Then I...
6
by: Jonathan | last post by:
I want to save textarea contents to a mysql database with the paragraph breaks intact without having to type paragraph or break tags in HTML. How can I do that. So far, although it occurs naturally...
4
by: intl04 | last post by:
I have a memo field that is included in some Access reports I created. Is there some way for the memo field to display nicely formatted text, with line breaks between paragraphs? Or is it necessary...
2
by: Mike | last post by:
I need my textbox to work more smoothly with respect to line breaks. When I have data pulled from the database into a textbox there are hard line breaks at the end of each line (by definition how...
5
by: joelbyrd | last post by:
Didn't know exactly where to post this, but: How do I get line breaks in a textarea? I'm pulling text from a database, and this text definately has line breaks in it, because I replaced all the...
2
by: caspardh | last post by:
i was trying to code a morse code decipherer which workd fine except that the .txt file that i was converting had linebreaks built in, i cant get python to ignore the line breaks and i cant find any...
8
by: Harris Kosmidis | last post by:
It seems I cannot understand CSS, well. I have donw the following page: http://www.pennias.gr/home.php It's in greek but the context is of no importance. I used a big table to put in my page...
10
by: Itaichuk | last post by:
Hi I read in several CSS tutorials that block-level elements, such as <div& <pare rendered with an implicit line break before and after. I set to test this out using the following HTML: I...
1
by: =?ISO-8859-1?Q?thib=B4?= | last post by:
Hi, Taking a closer look to highlight_file() lastly, I found out that its line break policy was a bit.. strange. <?php # highlight_file() line breaks test $f = fopen('highlight_file_test',...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.