Saving to an ansi encoded text/csv file

Have a web form and I'm populating an external file with the data.
When the submitted data contains a right-apostrophe, it lays down a ’ in it's place.
How can I (or can I) convert that so that it's the same character in the text file, or does it not support that character in ANSI encoding?
LVL 67
sirbountyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
"I'm populating an external file with the data."
How are you creating this file?
0
sirbountyAuthor Commented:
Streamwriter...

If File.Exists(filePath) Then
    Try
        Dim sw As StreamWriter = File.AppendText(filePath)
        sw.WriteLine(DataEntry.ToString)
        sw.Flush()
        sw.Close()
    Catch ex As Exception
    End Try
End If

Open in new window

0
Bob LearnedCommented:
Try using encoding:

Using writer As New StreamWriter(fileName, append, New UTF8Encoding(False))
    writer.Write(saveString)
    writer.Close()
End Using

Open in new window

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

sirbountyAuthor Commented:
Still adding the 3 character adjustment. :\
Though I did make some changes to the web.config last week... I"ll remove that and retry.
0
sirbountyAuthor Commented:
Unfortunately, it seems to end with the same results no matter what I try.
I'm not sure if I can change the encoding of the text file to something else.
This is still part of that other project that you've been helping me with.  This is the csv file that gets uploaded.
In order to have a match of the email subject, I need this to be what is submitted.  If it differs, it won't find the item.  My other thought was to truncate it at the invalid character - at least that gets me partial subject data...
0
Bob LearnedCommented:
There are other encodings that you should try:

Default = ANSI
Unicode
0
sirbountyAuthor Commented:
Yeah, I had already given that a try.  One inserted spaces on either side of every character, and used a single funky character in place of the apostrophe.  I think ANSI replaced it with a ? character...

It's weird tho - if I open the file in notepad and choose file/save as - it shows ANSI.
I can copy/paste the data there with no problems.  Not understanding why I can't do that through code.
0
Bob LearnedCommented:
" I think ANSI replaced it with a ? character"
That sounds more like ASCII, than ANSI.

What is the code for the apostrophe character?
0
sirbountyAuthor Commented:
You mean - chr(146)?
0
sirbountyAuthor Commented:
I didn't see an ansi encoding
0
Bob LearnedCommented:
That would be the extended ASCII character code, which is Latin-1 (ISO-8859-1).

Encoding.GetEncoding("ISO-8859-1")
0
Bob LearnedCommented:
Encoding.Default = ANSI code page
0
sirbountyAuthor Commented:
Are you saying I should use Encoding.GetEncoding("ISO-8859-1") in my streamwriter?
0
Bob LearnedCommented:
Yes, I was trying to say, "Give ISO-8859-1 encoding a try with the StreamWriter".
0
sirbountyAuthor Commented:
Now that 'looks' better...
Original: don’t
Final: don't

But the first apostrophe is chr(146), the second is chr(39).
0
Bob LearnedCommented:
That is confusing.  I am not sure how to deal with that statement.  Is the character getting converted?
0
sirbountyAuthor Commented:
"Don't" is the word that's tripping me up.   The apostrophe is a right-apostrophe (chr(146).
If I copy it from the email request and paste it into notepad/the csv it display correctly.

If I add it via my web form using a streamwriter, it converts it to a single apostrophe, chr(39).
I don't know that I want it converted - I'd rather it be the same exact character so that when the email is searched for in the database, it finds it by the exact same subject.
0
Bob LearnedCommented:
One last experiment would be to try Encoding.Default instead of Latin-1 encoding with the StreamWriter.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sirbountyAuthor Commented:
That's not what is used when you don't specify encoding?
0
Bob LearnedCommented:
The default, without encoding is actually UTF-8 without byte-order marker (BOM).

StreamWriter constructor (stream):
   
  Public Sub New(ByVal stream As System.IO.Stream)
            MyClass.New(stream, StreamWriter.UTF8NoBOM, 1024, False)
        End Sub

Open in new window

0
sirbountyAuthor Commented:
Encoding.Default seemed to do the trick.  Thanks much! :^)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.