How to convert FString to * char?

i have function where i recieve FString. I need send this to Socket server but function “send” work with const char only. Have any idea how i can do this?

Hi,

What string encoding is your socket expecting? If ASCII, you can do this:

auto ansi_login = StringCast<ANSICHAR>(*login);
auto ansi_password = StringCast<ANSICHAR>(*password);
send(my_sock, ansi_login.Get(), ansi_login.Length(), 0);
send(my_sock, ansi_password.Get(), ansi_password.Length(), 0);

If UTF-8, you can do this instead, as StringCast doesn’t currently work with our UTF8CHAR:

FTCHARToUTF8 ansi_login(*login);
FTCHARToUTF8 ansi_password(*password);
send(my_sock, ansi_login.Get(), ansi_login.Length(), 0);
send(my_sock, ansi_password.Get(), ansi_password.Length(), 0);

Also, FYI, you should generally pass your FStrings by const reference, to prevent unnecessary copies being made:

bool UMyGameInstance::CheckInputs(const FString& login, const FString& password)

Hope this helps,

thx a lot !

this does not work for persian or arabic characters. what should I use?