Jump to content
  • Advertisement
Sign in to follow this  
Bronco78th

C# streamwriter problem

This topic is 2704 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys,

Latest minor problem....at least this one is minor.

I have this code.

using (StreamWriter gentxt = new StreamWriter(saveFileDialog1.FileName))
{
for (int i = 0; i < contactlist.Count; i++)
{
gentxt.WriteLine(("Name:"),contactlist.Name);
gentxt.WriteLine("Mobile:",contactlist.Mobile);
gentxt.WriteLine(contactlist.Homephone);
}


That code generates this as a text document.


Name:
Mobile:
54346553456534[/quote]

oviously I want something like.

Name: John
Mobile: 432432565464
Homephone: 87998979969
Etc

Can I only have 1 item (argument) per Writeline or is there another way of doing it?

Cheers
John

Share this post


Link to post
Share on other sites
Advertisement

Hey guys,

Latest minor problem....at least this one is minor.

I have this code.

using (StreamWriter gentxt = new StreamWriter(saveFileDialog1.FileName))
{
for (int i = 0; i < contactlist.Count; i++)
{
gentxt.WriteLine(("Name:"),contactlist.Name);
gentxt.WriteLine("Mobile:",contactlist.Mobile);
gentxt.WriteLine(contactlist.Homephone);
}


That code generates this as a text document.


Name:
Mobile:
54346553456534


oviously I want something like.

Name: John
Mobile: 432432565464
Homephone: 87998979969
Etc

Can I only have 1 item (argument) per Writeline or is there another way of doing it?

Cheers
John
[/quote]

Only the first argument is for strings. Use something like:

gentxt.WriteLine("Name:" + contactlist.Name);

WriteLine(String, Object, Object)Writes the text representation of the specified objects, followed by the current line terminator, to the standard output stream using the specified format information.

Share this post


Link to post
Share on other sites
Hey Slynk

Cheers for the hasty reply.

Knew it had to be soemthing simple.

I think I tried (("Name:")+ contactlist.Name) but not without the brackets....the only version I seemed to have overlooked was the correct one. <_<

Many thanks anyway.

John

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!