9 Replies - 4484 Views - Last Post: 23 March 2012 - 04:55 PM Rate Topic: ***** 1 Votes

#1 Amenhoteph   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 15-March 12

Why won't this remove quotation marks from my string?

Posted 22 March 2012 - 01:36 PM

I'm writing a utility that loads one of three different formats of CSV files into a table. One of the formats has quotation marks which I want to remove. For some silly reason I thought that if I just did a String.Replace("\"","") on the string before I ran the split on ',' everything would end up looking the way I wanted it to.

The code below works and I am able to load the data into a table as-is, but the " marks are still present.

Ideas?

public List<string[]> parseCSV(string path)
      {
          List<string[]> parsedData = new List<string[]>();

          string line;
          string[] row;

              using (StreamReader readFile = new StreamReader(path))
              {
                  while ((line = readFile.ReadLine()) != null)
                  {
                      line.Replace("\"","");
                      row = line.Split(',');
                      parsedData.Add(row);
                  }
                  return parsedData;
              }
          
      }


Is This A Good Question/Topic? 0
  • +

Replies To: Why won't this remove quotation marks from my string?

#2 Ryano121   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1461
  • View blog
  • Posts: 3,289
  • Joined: 30-January 11

Re: Why won't this remove quotation marks from my string?

Posted 22 March 2012 - 01:39 PM

String are immutable so you have to put the result of the methods inside another/ the same string variable -

line.Replace("\"","");


Should be

line = line.Replace("\"","");

Was This Post Helpful? 2
  • +
  • -

#3 Amenhoteph   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 15-March 12

Re: Why won't this remove quotation marks from my string?

Posted 22 March 2012 - 02:01 PM

Works perfectly now. Thank you very much.
Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5103
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Why won't this remove quotation marks from my string?

Posted 22 March 2012 - 02:38 PM

Always start with the documentation. If you don't understand why something does or doesn't work, google search the method. In this case: https://www.google.c...=string.replace

The first result is this:

http://msdn.microsof...ng.replace.aspx

which links to the answer:

Quote

Returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string.


Learning to use the MSDN will save you hours and hours of waiting for people to tell you how things work on forums.
Was This Post Helpful? 1
  • +
  • -

#5 Amenhoteph   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 15-March 12

Re: Why won't this remove quotation marks from my string?

Posted 23 March 2012 - 12:48 PM

This is twice now that I've gotten a snotty (yes, snotty) reply from a Mod on this forum.

If you don't want people who are new to C# asking questions that are evading them then you might want to restrict membership a little better. I was having an error that I did not understand, it looked right to me on the screen, but I was obviously missing something. I am sure that there is more than one person here who has struggled over some buggy code for an hour only to realize that there was a misplaced comma they didn't see that was screwing up the whole block. Submitting a RTFM response after the problem was solved by a member of the forum who was glad to help serves no purpose other than inflate your ego.

Tell you what, go ahead and ban my account. If this is the type of crap I'm going to have to deal with while I try and transition to C# I'll find someplace else to post.
Was This Post Helpful? -1
  • +
  • -

#6 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6534
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Why won't this remove quotation marks from my string?

Posted 23 March 2012 - 01:31 PM

Amenhoteph: Let me say that I am appalled at your comment.

As the self-proclaimed king of snotty (yes 'snotty') around here I can tell you that Curtis Rutland was NOT.

He gave you advice on how you can find answers to common rookie problems by simply reading the documentation.

The goal was to help you know where to look so you didn't have to resort to the very time-consuming process of writing a question, explaining the situation, posting and then waiting... waiting... waiting.... In the hopes someone has an answer. If you know where to look then you can find answers magnitudes faster.

If you can't cope with someone talking to you like an adult, without every sentence being slanted to boost your ego and stroke your confidence then I suggest you start looking at a different career field. Software Development is not known for employers who blow rainbows and unicorns up your skirt. It is a face-paced, high-pressure, short deadline industry where everyone is overworked and highly amped on caffeine. Your employers will be quick to tell you to pull your head out of your ass, and slow to praise you for doing what they pay you to do. If your emotional skill-set isn't equipped for that then you need to either buck up or cross train to something else.

Curtis did not call you names, did not insult you, did not talk down to you, did not denegrate you. Like the core group of volunteers here, he is a senior software developer that graciously donates his time to mentor the next generation who want to be come professional software engineers. I think you should take a moment to consider how fortunate you are to have resources like this site and these people at your fingertips. The people you are asking for help from didn't have it so easy and learned everything through hundreds of hours of trial and error. Many of us literally wrote the books that your generation is now learning from. And you have the ability to just drop a note on these peoples' desks any time you like. That's such an amazing opportunity for you. Don't fuck it up for yourself.

This post has been edited by tlhIn`toq: 23 March 2012 - 01:33 PM

Was This Post Helpful? 1
  • +
  • -

#7 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6534
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Why won't this remove quotation marks from my string?

Posted 23 March 2012 - 01:52 PM

Update:
The need to teach people how to search is not limited to just you. It comes up here often enough that I had to write a tutorial for it. So don't take it personally. While some call this the 'Google Generation', it does seem that this should be called the "Too-lazy-to-Google generation."


I have to provide this tip more often than I can count.



Finding answers to specific problems:
Spoiler



This post has been edited by tlhIn`toq: 23 March 2012 - 01:52 PM

Was This Post Helpful? 0
  • +
  • -

#8 Amenhoteph   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 15-March 12

Re: Why won't this remove quotation marks from my string?

Posted 23 March 2012 - 02:11 PM

tlhIn`toq,

I don't remember asking for your opinion, but I'll respond since you took the time. You made a lot of sweeping assumptions and I'm going to clear them up for you.

I'm not looking into software dev as a new career, I just need to write a couple of utilities to make my daily life easier. If I had wanted to be a programmer I would have gone that route rather than spending the past 10 years in the United States Army. While you and yours were writing books, sipping Starbucks and pretending to be characters in Star Trek, I was humping a rifle through the sand. So, I tell you what, go upstairs to your Mom's fridge and get another soda and write another tutorial. I'm sure the world will be a better place as a result. Punk.

This post has been edited by tlhIn`toq: 23 March 2012 - 04:43 PM

Was This Post Helpful? 0
  • +
  • -

#9 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5103
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Why won't this remove quotation marks from my string?

Posted 23 March 2012 - 04:36 PM

Quote

If you don't want people who are new to C# asking questions that are evading them then you might want to restrict membership a little better. I was having an error that I did not understand, it looked right to me on the screen, but I was obviously missing something. I am sure that there is more than one person here who has struggled over some buggy code for an hour only to realize that there was a misplaced comma they didn't see that was screwing up the whole block. Submitting a RTFM response after the problem was solved by a member of the forum who was glad to help serves no purpose other than inflate your ego.


Well, you're perfectly entitled to your own opinion, but I think you misunderstood my intentions. My goal is not to help people solve single problems. My goal is to help people become better programmers. And sometimes that means teaching people how to help themselves. So yeah, I sometimes explain the most convenient ways that people can help themselves, like explaining what google terms to use, and what websites contain what documentation, since when I was a new programmer, I didn't know these things. I didn't know how useful the MSDN was. So, I figure, share the love.

I don't want to just solve a problem. I want to increase a person's ability to be a capable programmer. If you interpret that as snotty, that's your hangup. Perhaps you have a chip on your shoulder. But regardless, I think my status and reputation here speak for itself. If I regularly provided "snotty" answers, I wouldn't have been selected as a staff member.

Anyway, good luck in your future endeavors. By the way, personal attacks on members will not be tolerated, so tone it down.
Was This Post Helpful? 4
  • +
  • -

#10 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6534
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Why won't this remove quotation marks from my string?

Posted 23 March 2012 - 04:55 PM

View PostAmenhoteph, on 23 March 2012 - 03:11 PM, said:

tlhIn`toq,

I don't remember asking for your opinion, but I'll respond since you took the time. You made a lot of sweeping assumptions and I'm going to clear them up for you.

I'm not looking into software dev as a new career, I just need to write a couple of utilities to make my daily life easier. If I had wanted to be a programmer I would have gone that route rather than spending the past 10 years in the United States Army. While you and yours were writing books, sipping Starbucks and pretending to be characters in Star Trek, I was humping a rifle through the sand. So, I tell you what, go upstairs to your Mom's fridge and get another soda and write another tutorial. I'm sure the world will be a better place as a result. Punk.


Speaking of assumptions... I must say I'm now more ashamed than anything else: That coming from being a retired US Army 32G.

I would have expected those years in the military to make your more self sufficient... More determined... certainly a bit thicker skinned to comments from cyber-stranger that are nothing more than blips on a screen.

I would have expected more of a 'soldier' mentality that understood standing up for, and the defense of others and taking a stand against wrong. But like other noble warrior professions such as law enforcement, the military often draws people to it so they can be part of the largest gang around and have official backing for their bullying nature and tactics.

I wish you the best of luck in your project, and your future.

From one soldier to another: Thank you for your part serving our country.

From one human being to another: Perhaps you should see someone to discuss whatever deeper issues are causing this massive chip on your shoulder.

This post has been edited by tlhIn`toq: 23 March 2012 - 04:56 PM

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1