Juvarunst
(Juvarunst)
December 31, 2017, 2:23pm
1
I encountered a problem sending the string
this’s my code:
Socket->Send((uint8*)TCHAR_TO_UTF8(*StringValue), StringValue.Len(), SocketSent);
I use FString.Len() to get the length of FString
if “StringValue” is English , this’s normal
but if “StringValue” it’s Chinese , this’s wrong , it’s length is too short
Juvarunst
(Juvarunst)
December 31, 2017, 2:25pm
2
Maybe Chinese accounted for more bytes?
FString is just an array of TCHARs. FString::Len() will return the size of that array. If you see more characters than FString::Len() is reporting then most likely there are two (or more) Chinese characters within the same TCHAR in the FString array.
Juvarunst
(Juvarunst)
December 31, 2017, 2:48pm
4
Yes, I found that sometimes 2 bytes, sometimes 3 bytes, sometimes 4 bytes
Juvarunst
(Juvarunst)
December 31, 2017, 3:03pm
5
I checked, one TCHAR is one Chinese character
Oh. I think it might be because you are converting from TCHAR to byte. Try StringValue.Len() * sizeof(TCHAR)
Juvarunst
(Juvarunst)
December 31, 2017, 3:54pm
8
This’s my code:
Socket->Send((uint8*)TCHAR_TO_UTF8(*StringValue), StringValue.Len()*sizeof(TCHAR), SocketSent);
Juvarunst
(Juvarunst)
December 31, 2017, 4:08pm
9
I use the “啊” character to test
The “啊” character originally should account for 3 bytes
But here only calculated 2 bytes
Not sure why it would be three bytes. Try using “FTCHARToUTF8”. I see in the engine source that this is how they convert. Here’s what you should try:
FTCHARToUTF8 Converted(*StringValue);
Socket->Send((uint8*)Converted.Get(), Converted.Length(), SocketSent);
You will need to add #include "StringConv.h"
as well
1 Like
Juvarunst
(Juvarunst)
December 31, 2017, 4:31pm
11
I am trying to find a solution
Juvarunst
(Juvarunst)
December 31, 2017, 4:43pm
13
cool ~ , it work, thank you
Cool indeed. You’re welcome.
Smove66
(Smove66)
January 27, 2021, 8:14am
16
I have been looking for this solution for hours. Thanks a lot!