littlebigman
Well-known member
- Joined
- Jan 5, 2010
- Messages
- 75
- Programming Experience
- Beginner
Hello
I've been googling and trying different ways for an hour, but still can't find how to convert an UTF-8 string into ANSI that System.IO.StreamWriter() will accept.
Using the WebClient object, I'm downloading a web page encoded in UTF-8, and need to convert it to ANSI (I assume StreamWriter() expects ANSI) so that I can save it into a file using System.IO.StreamWriter().
The following turns accented characters from Unicode to ??:
If someone has some working code handy, I'm interested.
Thank you.
I've been googling and trying different ways for an hour, but still can't find how to convert an UTF-8 string into ANSI that System.IO.StreamWriter() will accept.
Using the WebClient object, I'm downloading a web page encoded in UTF-8, and need to convert it to ANSI (I assume StreamWriter() expects ANSI) so that I can save it into a file using System.IO.StreamWriter().
The following turns accented characters from Unicode to ??:
VB.NET:
Sub AlertStringDownloaded(ByVal sender As Object, ByVal e As DownloadStringCompletedEventArgs)
If e.Cancelled = False AndAlso e.Error Is Nothing Then
Dim title As Regex = New Regex("<title>(.+?)</title>")
Dim m As Match
m = title.Match(CStr(e.Result))
If m.Success Then
Dim resbytes() As Byte = Encoding.UTF8.GetBytes(m.Groups(1).Value)
Dim Response As String = Encoding.Default.GetString(Encoding.Convert(Encoding.UTF8, Encoding.ASCII, resbytes))
'Illegal characters in path : ??
Dim objWriter As New System.IO.StreamWriter("c:\" & Response & ".txt")
objWriter.Write(CStr(e.Result))
objWriter.Close()
End If
End Sub
If someone has some working code handy, I'm interested.
Thank you.