Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 132,683 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,230 people online right now. Registration is fast and FREE... Join Now!




Line changment in streamWriter and sensitive replace method

 
Reply to this topicStart new topic

Line changment in streamWriter and sensitive replace method

Dumpen
post 25 May, 2008 - 03:53 AM
Post #1


New D.I.C Head

*
Joined: 21 Mar, 2008
Posts: 40

Hello.

I have 2 questions for you

Question 1:
I got this method:

CODE
private void writeData()
        {
            StreamWriter writer = new StreamWriter(saveMonsterSetBase.FileName, false);

            for (int i = 0; i < MonsterSetBaseDataArray.Count; i++)
            {
                writer.Write(MonsterSetBaseDataArray[i]);
            }

            writer.Close();
        }


Which sort of works

It writes data from my arraylist to a file

The problem is it writes it in one line.

If my arraylist is like this:
line 1
line 2
line 3

It writes in the file like this:
line 1 line 2 line 3

How can I make a line changment?


Question 2:
I have a string that looks like this:
string testString = "1 10";

and I want to replace 1 and 10 with something

I replace it like this:
testString.Replace("1", "One").Replace("10", "Ten");

But the problem is that the output for 10 comes out as OneTen

Is there any way to replace 1 as just One and 10 as just Ten?
User is offlineProfile CardPM

Go to the top of the page

Dumpen
post 25 May, 2008 - 04:35 AM
Post #2


New D.I.C Head

*
Joined: 21 Mar, 2008
Posts: 40

Soloution found:
1:
[writer.WriteLine(MonsterSetBaseDataArray);

2:
testString.Replace("10", "Ten").Replace("1", "One");
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 25 May, 2008 - 06:14 AM
Post #3


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,933



Thanked 118 times

Dream Kudos: 8525

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


Your original loop would have worked when using WriteLine()


csharp

private void writeData()
{
StreamWriter writer = new StreamWriter(saveMonsterSetBase.FileName, false);

for (int i = 0; i < MonsterSetBaseDataArray.Count; i++)
{
writer.WriteLine(MonsterSetBaseDataArray[i]);
}

writer.Close();
}
User is offlineProfile CardPM

Go to the top of the page

Dumpen
post 25 May, 2008 - 07:04 AM
Post #4


New D.I.C Head

*
Joined: 21 Mar, 2008
Posts: 40

Thats what I did tongue.gif

I just replaced write with writeline, but thanks smile.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 06:52AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month