Click here to Skip to main content
16,012,107 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
[Solved: ok, it may not have been completely solved, but it was re-posted under the correct article]

I have a text file in which at the line where is a "xxx "xx" xxxx" condition.

the text file is ";" seprated when the csv reader goes to read this line as follows

"123344";"0897778";"977686";"xxx "xxx" xxx";"1231231";"12312";""

at the bold thing it gives an exception "MalformedCsvException" and says csv is currptes or some thing.

what i was trying to solve this problem is in the method in the csvreader.cs
at ReadField()
AT
Label_03F3:
                while (num5 < this._bufferLength)
                {
                    if (_nextFieldStart + 1 == 41 || _nextFieldStart + 1==42)
                    {
                    }
                    char ch2 = this._buffer[num5];
                    if (flag2)
                    {
                        flag2 = false;
                        num4 = num5;
                    }
                    else if ((ch2 == this._escape) && (((this._escape != this._quote) || (((num5 + 1) < this._bufferLength) && (this._buffer[num5 + 1] == this._quote))) || (((num5 + 1) == this._bufferLength) && (this._reader.Peek() == this._quote))))
                    {
                        if (!discardValue)
                        {
                            str = str + new string(this._buffer, num4, num5 - num4);
                        }
                        flag2 = true;
                    }
                    //else if (ch2 == this._quote && (((num5 + 1) < this._bufferLength) && (this._reader.Peek() != this._quote)))//here i need to add condition of 
                    //{
                    //    //if ((ch2 == this._quote) && (this._buffer[num5 + 1] == this._delimiter))
                    //    //{
                    //    //    flag = false;
                    //    //    break;
                    //    //}
                    //    //else if ((ch2 == this._quote) && (this._buffer[num5 + 1] != this._quote) && (this._buffer[num5 + 1] != this._delimiter))//insted of _quote check a character or space
                    //    //{
                    //    //    flag = false;
                            
                    //    //}
                    //    //else
                    //    //{
                    //        //flag = false;
                    //       // break;
                    //    //}
                        
                    //}

                    //else if ((ch2 == this._quote) && (this._buffer[num5 + 1] == this._delimiter))                      
                    //{
                    //    flag = false;
                    //    break;
                    //}
                    else if (ch2 == this._quote) 
                    {
                        flag = false;
                        break;
                    }
                    num5++;
                }


i was trying to solve it but it come up with increas of filed count.

i Hope You can help me in this case

[edit]Code block added for formatting[/edit]
Posted
Updated 1-Jul-10 5:47am
v3

1 solution

Am I right in assuming that this is about a CSV reader article?
If so, don't post this under Quick Answers - if you got the code from an article, then there is a "new message" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to speak to them.
Posting this here relies on them "dropping by" and realising it is for them.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900