![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Converting text between various encodings Hi, I'm playing with converting text strings between various encodings like Unicode and UTF8 and UTF7. One tool I've found that seems to do at least some of this is the oleprn.olecvt object (on W2K and later I think) which has ToUnicode and ToUtf8 methods. TLViewer shows that the ToUnicode method takes two arguments, a string to be converted and a long integer representing the codepage of the string to be converted (I think), and returns a Unicode string. It shows that the ToUtf8 method takes one argument, apparently a little endian Unicode string. I'm hoping that someone will post a url for some documentation on this oleprn.olecvt object. TLViewer indicates a lot of functionality, with coclasses having a lot of printer functionality. But I'm mostly interested in whether the ToUnicode method can convert only from UTF8 or from any encoding for which my computer has a codepage number. Maybe this function: Function fsUTF8ToUnicode(sUTF8String, lCodePage) should really be called an any-encoding to Unicode routine. Anyhow, here is a simple script that converts a Unicode character to UTF8 and back to Unicode: Option Explicit Dim sUnicode: sUnicode = ChrW(&H2018) Dim sUTF8, sNewUnicode sUTF8 = fsUnicodeToUTF8(sUnicode) MsgBox "Original Unicode = " & sUnicode & _ " (&H" & Hex(ascW(sUnicode)) & ")" & _ vbcrlf & "UTF8: " & sUTF8 sNewUnicode = fsUTF8ToUnicode(sUTF8, 65001) MsgBox "Original Unicode = " & sUnicode & _ " (&H" & Hex(ascW(sUnicode)) & ")" & _ vbcrlf & "UTF8: " & sUTF8 & vbCrLf & _ "New Unicode = " & sNewUnicode & _ " (&H" & Hex(ascW(sNewUnicode)) & ")" Function fsUnicodeToUTF8(sUnicodeString) fsUnicodeToUTF8 = CreateObject("OlePrn.OleCvt")._ ToUtf8(sUnicodeString) End Function 'fsUnicodeToUTF8(sUnicodeString) 'list of codepage numbers for various encodings. 'http://www.motobit.com/help/scptutl/cl68.htm Function fsUTF8ToUnicode(sUTF8String, lCodePage) fsUTF8ToUnicode = CreateObject("OlePrn.OleCvt")._ ToUnicode(sUTF8String, lCodePage) End Function 'fsUTF8ToUnicode(sUTF8String, lCodePage) -Paul Randall |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Howto: Add lines of text from a specific point in a text file.. | VB Script | |||
| Converting audio into text | Vista General | |||
| How do I read a text file and sort text by fixed positions? | PowerShell | |||
| Other encodings in powershell? | PowerShell | |||
| Cmdlets and Supporting Encodings | PowerShell | |||