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. Visual Basic
  4. Removing BOM from string

Removing BOM from string

Scheduled Pinned Locked Moved Visual Basic
question
7 Posts 4 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.
  • J Offline
    J Offline
    Jay Royall
    wrote on last edited by
    #1

    Hi, I have developed a rountine that builds a string using the StringBuilder class and then creates a CSV file from the string. The CSV file is then used to import data into another application. However, after creating the CSV file there is BOM at the start of the file which is preventing me from importing into the 3rd party application. My question is how can I create the CSV file without the BOM? Thanks for your time.

    C D 2 Replies Last reply
    0
    • J Jay Royall

      Hi, I have developed a rountine that builds a string using the StringBuilder class and then creates a CSV file from the string. The CSV file is then used to import data into another application. However, after creating the CSV file there is BOM at the start of the file which is preventing me from importing into the 3rd party application. My question is how can I create the CSV file without the BOM? Thanks for your time.

      C Offline
      C Offline
      Covean
      wrote on last edited by
      #2

      Can you please post some code snippets (like creating this string by your StringBuilder, writing the CSV file, ...), cause I never heard of such a strange behaviour.

      Greetings Covean

      1 Reply Last reply
      0
      • J Jay Royall

        Hi, I have developed a rountine that builds a string using the StringBuilder class and then creates a CSV file from the string. The CSV file is then used to import data into another application. However, after creating the CSV file there is BOM at the start of the file which is preventing me from importing into the 3rd party application. My question is how can I create the CSV file without the BOM? Thanks for your time.

        D Offline
        D Offline
        DaveAuld
        wrote on last edited by
        #3

        BOM will only appear if you have put it there. Definitely need to see code to work out where it is being generated.

        Dave Don't forget to vote on messages! Find Me On: Web|Facebook|Twitter|LinkedIn Waving? dave.m.auld[at]googlewave.com

        J 1 Reply Last reply
        0
        • D DaveAuld

          BOM will only appear if you have put it there. Definitely need to see code to work out where it is being generated.

          Dave Don't forget to vote on messages! Find Me On: Web|Facebook|Twitter|LinkedIn Waving? dave.m.auld[at]googlewave.com

          J Offline
          J Offline
          Jay Royall
          wrote on last edited by
          #4

          Thanks both of you but I have resolved it. I was using:

          Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFile, False)

          which was creating the file as UFT-8 which seemd to insert the BOM. I have changed it to:

          Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFile, False, System.Text.Encoding.ASCII)

          which doesn't insert the BOM. Thanks for your time.

          L 1 Reply Last reply
          0
          • J Jay Royall

            Thanks both of you but I have resolved it. I was using:

            Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFile, False)

            which was creating the file as UFT-8 which seemd to insert the BOM. I have changed it to:

            Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFile, False, System.Text.Encoding.ASCII)

            which doesn't insert the BOM. Thanks for your time.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            As you discovered there is a difference between UTF-8 and ASCII. UTF-8 files always have the header 0xEF 0xBB 0xBF so any program reading text files should check for this and not just assume the content is pure ASCII. C# programs tend to handle this automatically in most cases.

            MVP 2010 - are they mad?

            J 1 Reply Last reply
            0
            • L Lost User

              As you discovered there is a difference between UTF-8 and ASCII. UTF-8 files always have the header 0xEF 0xBB 0xBF so any program reading text files should check for this and not just assume the content is pure ASCII. C# programs tend to handle this automatically in most cases.

              MVP 2010 - are they mad?

              J Offline
              J Offline
              Jay Royall
              wrote on last edited by
              #6

              Another lesson learned :D Thanks

              L 1 Reply Last reply
              0
              • J Jay Royall

                Another lesson learned :D Thanks

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Liqz wrote:

                Another lesson learned

                Same here, I learned it the hard way ... ;)

                MVP 2010 - are they mad?

                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