Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Line changment in streamWriter and sensitive replace method

Line changment in streamWriter and sensitive replace method

Scheduled Pinned Locked Moved C#
questionhelp
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Casper Hansen
    wrote on last edited by
    #1

    Hello. I have 2 questions for you Question 1: I got this method:

    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?

    C 1 Reply Last reply
    0
    • C Casper Hansen

      Hello. I have 2 questions for you Question 1: I got this method:

      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?

      C Offline
      C Offline
      Casper Hansen
      wrote on last edited by
      #2

      Soloution found: 1: [writer.WriteLine(MonsterSetBaseDataArray); 2: testString.Replace("10", "Ten").Replace("1", "One");

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups