Convert FString to TCHAR

How do I convert a FString to a TCHAR?

Example: TCHAR * wavLink = MyTextVariable

Not working: TCHAR * wavLink = ANSI_TO_TCHAR(MyTextVariable);

I get cannot convert from β€˜const TCHAR *’ to 'TCHAR *

FString UWav::Wav(FString MyTextVariable)
{
	TCHAR* wavLink = *MyTextVariable;
	return "Done";
}
1 Like

Hi Taurian,

To convert an FString to a TCHAR array, all you need to do is dereference the FString variable. Using your example, this should work: TCHAR* wavLink = *MyTextVariable;

4 Likes

Sorry, I forgot to include const in my code snippet. It should have read: const TCHAR* wavLink = *MyTextVariable;

The FString dereferences as a const TCHAR array because it is unsafe to make modifications to the array directly.

4 Likes

Niiice. Thanks.

Thx , it works

/**
* Get pointer to the string
*
* @Return Pointer to Array of TCHAR if Num, otherwise the empty string
/
FORCEINLINE const TCHAR
operator*() const
{
return Data.Num() ? Data.GetData() : TEXT(β€œβ€);
}

From UE4.19, it seems *FString can only work form num string.

1 Like