Guys,
i wonder, if somewhere already exists a tool, which takes a string from the clipboard and returns it re-encoded, e.g. from UTF-8 to 1252 - yes, i know there may be problems with exotic languages, but that's not relevant in my use case.
Sample:
In -> Tragfläche ONE, final 3 Pendel-Höhenleitwerk
Out -> Tragfläche ONE, final 3 Pendel-Höhenleitwerk
I think i can write something q&d myself, but would rather use what already exists
Codepage swapping
Codepage swapping
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Codepage swapping
Hello Karl,
Somewhere in my program I am using this function, no idea where I got it from:
This calls MultiByteToWideChar which is documented here:
https://docs.microsoft.com/en-us/window ... towidechar
An example is this:
and the dwFrom and dwTo constants like CP_AP or CP_UTF8 are explained in the above page.
I hope this helps you.
Dick
Somewhere in my program I am using this function, no idea where I got it from:
Code: Select all
FUNCTION ConvertFromCodePageToCodePage(cString AS STRING, dwFrom AS DWORD, dwTo AS DWORD) AS STRING
LOCAL pUStr AS PTR
LOCAL pBuffer AS PTR
LOCAL nLen,nULen AS LONG
// Convert VO string from dynamic memory to fixed memory
nLen := LONG(SLen(cString))
pBuffer := MemAlloc(DWORD(nLen))
MemCopyString(pBuffer,cString,DWORD(nLen))
// Determine length of Unicode string
// And allocate enough space to hold it
nULen := MultiByteToWideChar(dwFrom,0,pBuffer,nLen,NULL_PTR, 0)
pUStr := SysAllocStringLen(NULL_PTR,DWORD(nULen))
// Convert Fixed memory Ansi string to Fixed memory Unicode string
MultiByteToWideChar(dwFrom,0,pBuffer,nLen,pUStr,nULen)
// Now determine size needed for ANSI string
nLen := WideCharToMultiByte(dwTo,0,pUStr,nULen,NULL_PTR,0, NULL,NULL)
// Allocate Fixed memory buffer to hold the UTF8 string
pBuffer := MemRealloc(pBuffer, DWORD(nLen+1))
// Convert Unicode to Ansi
nLen := WideCharToMultiByte(dwTo,0,pUStr,nULen,pBuffer,nLen ,NULL,NULL)
// Convert fixed memory buffer to dynamic memory string
cString := Mem2String(pBuffer,DWORD(nLen))
// Release fixed memory buffer
MemFree(pBuffer)
// Release the Unicode String
SysFreeString(pUStr)
RETURN cString
https://docs.microsoft.com/en-us/window ... towidechar
An example is this:
Code: Select all
cResult := ConvertFromCodePageToCodePage(SubStr2(cResult, 4), CP_UTF8, CP_ACP)
I hope this helps you.
Dick
Codepage swapping
Dick,
That code is part of the VO System Library (Util module)
I think I added it in 2004 or so.
Robert
That code is part of the VO System Library (Util module)
I think I added it in 2004 or so.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
Codepage swapping
Found it, thx
As it is ptr based, ie, requests unsafe code allowed, is there an X# Version?
As it is ptr based, ie, requests unsafe code allowed, is there an X# Version?
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Codepage swapping
Karl,
Look at the Encoding classes.
Then do something like this:
- Retrieve the encoding for the source string
- Use GetBytes() to retrieve the bytes
- Retrieve the encoding for the target string
- Use GetString() to create the string from the bytes
Robert
Look at the Encoding classes.
Then do something like this:
- Retrieve the encoding for the source string
- Use GetBytes() to retrieve the bytes
- Retrieve the encoding for the target string
- Use GetString() to create the string from the bytes
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
Codepage swapping
Hello Robert, Karl,
Ah, I had it as a separate function without my usual comment lines showing where it came from. I barely escaped a lawsuit :unsure:
Karl, you posted this in Chit-Chat so I wasn't sure if you needed VO or X#.
This example in MSDN shows you how to do it in C#:
https://docs.microsoft.com/en-us/dotnet ... em_Byte___
Dick
Ah, I had it as a separate function without my usual comment lines showing where it came from. I barely escaped a lawsuit :unsure:
Karl, you posted this in Chit-Chat so I wasn't sure if you needed VO or X#.
This example in MSDN shows you how to do it in C#:
https://docs.microsoft.com/en-us/dotnet ... em_Byte___
Dick