x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

how to get fstring size?

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

Product Version: UE 4.17
Tags:
more ▼

asked Dec 31 '17 at 02:23 PM in C++ Programming

avatar image

Juvarunst
90 19 21 27

avatar image Juvarunst Dec 31 '17 at 02:25 PM

Maybe Chinese accounted for more bytes?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Dec 31 '17 at 02:43 PM

avatar image

Jin_VE
4.4k 32 77 41

avatar image Juvarunst Dec 31 '17 at 02:48 PM

Yes, I found that sometimes 2 bytes, sometimes 3 bytes, sometimes 4 bytes

avatar image Juvarunst Dec 31 '17 at 03:03 PM

I checked, one TCHAR is one Chinese character

avatar image Jin_VE Dec 31 '17 at 03:24 PM

Oh. I think it might be because you are converting from TCHAR to byte. Try StringValue.Len() * sizeof(TCHAR)

avatar image Juvarunst Dec 31 '17 at 03:43 PM

I am trying

avatar image Juvarunst Dec 31 '17 at 04:08 PM

I use the "啊" character to test

The "啊" character originally should account for 3 bytes

But here only calculated 2 bytes

avatar image Jin_VE Dec 31 '17 at 04:31 PM

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

avatar image Juvarunst Dec 31 '17 at 04:32 PM

I'm trying

avatar image Juvarunst Dec 31 '17 at 04:43 PM

cool ~ , it work, thank you :)

avatar image Jin_VE Dec 31 '17 at 04:48 PM

Cool indeed. You're welcome.

avatar image Juvarunst Dec 31 '17 at 05:16 PM

:)

avatar image Juvarunst Dec 31 '17 at 04:31 PM

I am trying to find a solution

avatar image Juvarunst Dec 31 '17 at 03:54 PM

This's my code:

Socket->Send((uint8*)TCHAR_TO_UTF8(*StringValue), StringValue.Len()*sizeof(TCHAR), SocketSent);

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question