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. String Manipulation

String Manipulation

Scheduled Pinned Locked Moved C#
helpdata-structurestutorialquestion
10 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.
  • R Offline
    R Offline
    RB Emphasys
    wrote on last edited by
    #1

    I have a tuff question, and ill give anyone my first born child for an answer. Im reading a comma delimited text file. So i have strings that I read in that look like this, "test", "test2", "test3", well here is my problem. The file gets screwed up from time to time and throws in extra quotes whereever it wants. So I often get this ""test, """"test2"", . Im using the split function with a string array to split the line when i read it in, but i need to know how to remove those damn quotes from the strings. I have tried using the trim function and the replace function to no avail. Any help would be greatly appreciated. Thanks, Ryan

    L C G 4 Replies Last reply
    0
    • R RB Emphasys

      I have a tuff question, and ill give anyone my first born child for an answer. Im reading a comma delimited text file. So i have strings that I read in that look like this, "test", "test2", "test3", well here is my problem. The file gets screwed up from time to time and throws in extra quotes whereever it wants. So I often get this ""test, """"test2"", . Im using the split function with a string array to split the line when i read it in, but i need to know how to remove those damn quotes from the strings. I have tried using the trim function and the replace function to no avail. Any help would be greatly appreciated. Thanks, Ryan

      L Offline
      L Offline
      Le centriste
      wrote on last edited by
      #2

      Instead of trimming, I would try to find why the extra quotes get in the file. How do you produce the file, how do you read it? Do you have code samples to show?

      R 1 Reply Last reply
      0
      • L Le centriste

        Instead of trimming, I would try to find why the extra quotes get in the file. How do you produce the file, how do you read it? Do you have code samples to show?

        R Offline
        R Offline
        RB Emphasys
        wrote on last edited by
        #3

        Well that is part of the problem. This is an add on to an already released product, and they have no intention of fixing the issue with the current product, some Im stuck with what it gives me.

        1 Reply Last reply
        0
        • R RB Emphasys

          I have a tuff question, and ill give anyone my first born child for an answer. Im reading a comma delimited text file. So i have strings that I read in that look like this, "test", "test2", "test3", well here is my problem. The file gets screwed up from time to time and throws in extra quotes whereever it wants. So I often get this ""test, """"test2"", . Im using the split function with a string array to split the line when i read it in, but i need to know how to remove those damn quotes from the strings. I have tried using the trim function and the replace function to no avail. Any help would be greatly appreciated. Thanks, Ryan

          C Offline
          C Offline
          Chris Jobson
          wrote on last edited by
          #4

          Maybe I'm missing something, but do you need the quotes at all (i.e. do any of the strings contain embedded commas)? If not then why not remove all the quotes first (using Replace), then use Split to break up the line on the commas? If the strings can contain embedded commas then it's harder. You say that it "throws in extra quotes whenever it wants", but then in your example its actually omitted a quote as well (between 'test' and the comma immediately after it). Does this really happen or was this an error in the example? Also, can it really add extra quotes "anywhere" (including in the middle of the text strings), or does it simply replace one quote by one or more quotes? Knowing the exact nature of the problem would help in trying to find a solution. Chris Jobson

          R 1 Reply Last reply
          0
          • C Chris Jobson

            Maybe I'm missing something, but do you need the quotes at all (i.e. do any of the strings contain embedded commas)? If not then why not remove all the quotes first (using Replace), then use Split to break up the line on the commas? If the strings can contain embedded commas then it's harder. You say that it "throws in extra quotes whenever it wants", but then in your example its actually omitted a quote as well (between 'test' and the comma immediately after it). Does this really happen or was this an error in the example? Also, can it really add extra quotes "anywhere" (including in the middle of the text strings), or does it simply replace one quote by one or more quotes? Knowing the exact nature of the problem would help in trying to find a solution. Chris Jobson

            R Offline
            R Offline
            RB Emphasys
            wrote on last edited by
            #5

            I want to remove all of the quotes, thats my goal. I have also tried using the replace function with both character and string overloads, but it doesnt seem to work, Im fairly new to c# so I apoligize for any newbie questions in advance. I was attempting to do something similar to this, string.replace(", null) or string.replace(char [] {'"'}, null), and I had no luck. If someone could give me directions on how to remove quotes or tick marks from a string my problem would be solved. Thanks for your patience. Ryan

            L C 2 Replies Last reply
            0
            • R RB Emphasys

              I want to remove all of the quotes, thats my goal. I have also tried using the replace function with both character and string overloads, but it doesnt seem to work, Im fairly new to c# so I apoligize for any newbie questions in advance. I was attempting to do something similar to this, string.replace(", null) or string.replace(char [] {'"'}, null), and I had no luck. If someone could give me directions on how to remove quotes or tick marks from a string my problem would be solved. Thanks for your patience. Ryan

              L Offline
              L Offline
              Le centriste
              wrote on last edited by
              #6

              String.Replace("\"", null);

              1 Reply Last reply
              0
              • R RB Emphasys

                I have a tuff question, and ill give anyone my first born child for an answer. Im reading a comma delimited text file. So i have strings that I read in that look like this, "test", "test2", "test3", well here is my problem. The file gets screwed up from time to time and throws in extra quotes whereever it wants. So I often get this ""test, """"test2"", . Im using the split function with a string array to split the line when i read it in, but i need to know how to remove those damn quotes from the strings. I have tried using the trim function and the replace function to no avail. Any help would be greatly appreciated. Thanks, Ryan

                L Offline
                L Offline
                Le centriste
                wrote on last edited by
                #7

                String.Replace("\"", null);

                R 1 Reply Last reply
                0
                • R RB Emphasys

                  I have a tuff question, and ill give anyone my first born child for an answer. Im reading a comma delimited text file. So i have strings that I read in that look like this, "test", "test2", "test3", well here is my problem. The file gets screwed up from time to time and throws in extra quotes whereever it wants. So I often get this ""test, """"test2"", . Im using the split function with a string array to split the line when i read it in, but i need to know how to remove those damn quotes from the strings. I have tried using the trim function and the replace function to no avail. Any help would be greatly appreciated. Thanks, Ryan

                  G Offline
                  G Offline
                  Giles
                  wrote on last edited by
                  #8

                  Sounds like a really good time to learn Regex'es.


                  Shameless Plug - Distributed Database Transactions in .NET using COM+

                  1 Reply Last reply
                  0
                  • L Le centriste

                    String.Replace("\"", null);

                    R Offline
                    R Offline
                    RB Emphasys
                    wrote on last edited by
                    #9

                    THANKS!!!!!!!!!!!

                    1 Reply Last reply
                    0
                    • R RB Emphasys

                      I want to remove all of the quotes, thats my goal. I have also tried using the replace function with both character and string overloads, but it doesnt seem to work, Im fairly new to c# so I apoligize for any newbie questions in advance. I was attempting to do something similar to this, string.replace(", null) or string.replace(char [] {'"'}, null), and I had no luck. If someone could give me directions on how to remove quotes or tick marks from a string my problem would be solved. Thanks for your patience. Ryan

                      C Offline
                      C Offline
                      Chris Jobson
                      wrote on last edited by
                      #10

                      s.Replace("\"", "") will remove all the double-quote characters in s. Chris Jobson

                      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