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

Character line break



I want to write a line to a text file that looks like this
-----------------------------------------------
How can I do this without doing this manually and assigning it to a
variable.
Ex. string x = Char('-') * 80

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
3 1669
Hi,
Try to use PadRight, a function on the string object.

string s = "".PadRight(20, '-');

/Mats-Lennart
"John Sutor" <jo********@cinfin.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...


I want to write a line to a text file that looks like this
-----------------------------------------------
How can I do this without doing this manually and assigning it to a
variable.
Ex. string x = Char('-') * 80

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
If i understand you right, you want to repeat a character automatically.
Then, try the cool overloaded String constructor of signature:
...ctor ( char c, int count )

// Writes
"--------------------------------------------------------------------------------"
sw.WriteLine(new string('-', 80));

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"John Sutor" <jo********@cinfin.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...


I want to write a line to a text file that looks like this
-----------------------------------------------
How can I do this without doing this manually and assigning it to a
variable.
Ex. string x = Char('-') * 80

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #3

something like this?

string myLine = DrawLine ( 80 );

string DrawLine( int length )
{
StringBuilder sb = new StringBuilder();
for ( int x = 0; x < length; x++)
{
sb.Append("-");
}

return sb.ToString();
}

"John Sutor" <jo********@cinfin.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...


I want to write a line to a text file that looks like this
-----------------------------------------------
How can I do this without doing this manually and assigning it to a
variable.
Ex. string x = Char('-') * 80

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #4

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

Similar topics

3
by: Yazar Yolait | last post by:
I want to skip lines in a file that are blank and that start with "&". So I strip(None) them and then startswith("&") but the only problem is if the line has nothing but white space and I...
2
by: dont bother | last post by:
Hi Buddies, I am facing this problem and I dont know what to use as EOF in python: I want to read a file, and put all the individual words in a dictionary with their index: For example if the...
5
by: Wai Yip Tung | last post by:
When I do for line in fp: the line string usually has a '\n' at the end. In many cases I don't want the line break character. I can trim it using if line.endswith('\n'): line = line ...
0
by: Phillip Farber | last post by:
Hello, I'm posting here with a somewhat technical question in the hope of finding someone with experience coding C++ against the SP_API in OpenSP 1.5. I have an app that uses the SP_API to...
1
by: Matt | last post by:
What is the syntax for line break character in javascript?? For example, the following code will yield error " unterminated string constant." If I put the following in one line, then no error. ...
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
4
by: Water Cooler v2 | last post by:
Besides embedding <BR/>, like general purpose programming languages, I thought you could embed escape sequences such as \n or \r\n into string arguments to cause line breaks in JavaScript. To...
16
by: junky_fellow | last post by:
Is there any efficcient way of removing the newline character from the buffer read by fgets() ? Is there any library function that is similar to fgets() but also tells how many bytes it read...
26
by: Bert | last post by:
Hi, I'm unhappy: why doesn't this work? char enc; char temp; for(int i=0;i<10000;i++){ fscanf(in,"%s",&temp); if(temp=='#')break; else
1
by: mccalla | last post by:
Hi all, Tricky question. I know how to remove line break characters and spaces by using the code below: $message =~ s/\n//g; $message =~ s/\s//g;
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: 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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.