Log FString cast to TCHAR*

I’m trying to write an FTimeSpan to string, I added some zero padding and saved it as an FString.

const TCHAR* time = *FormatTime(timeAtPause);
UE_LOG(LogClass, Log, TEXT("%s"), time);


Here is format time:
    FString AMorganFreemanActor::FormatTime(FTimespan time) {
    	FString result = PadZero(time.GetMinutes()) + ":" + PadZero(time.GetSeconds()) + ":" + (time.GetFractionMilli()+"");
    	const TCHAR* myResult =  *result;
    	return myResult;
    }

I think that dereferencing FString causes the weird characters instead of numbers. I’m not sure how to cast FString to TCHAR. In Java it would be aString.toCharArray() ;

Why reinvent the Wheel? There is already a ToString method on TimeSpan that also supports formating.

return ToString(TEXT("%m:%s:%f"));

Btw the Problem is how you Build the FString not the dereferncing :stuck_out_tongue_winking_eye:

All formating options Screenshot - d59741a3f7d46ab095e7c0ec89c3568a - Gyazo

FString still needs to be converted to TCHAR* ,
This:

UE_LOG(LogTemp, Warning, TEXT("%s"), timeAtPause.ToString(TEXT("%m:%s:%f")));

gives the error :

non-portable use of class 'FString' as an argument to a variadic function	

this:

const TCHAR* test = *timeAtPause.ToString(TEXT("%m:%s:%f"));
	UE_LOG(LogTemp, Warning, TEXT("%s"), test);

is my attempt at converting.
When I try to convert , I get this again with the weird chars:

My guess is that it is the dereferencing that does it. From what I read , FString is a wrapper around TCHARs , so… it might work to take the characters out one by one and convert to tchar then reassemble. Unless there’s a better way.

UE_LOG(LogTemp, Warning, TEXT("%s"), *timeAtPause.ToString(TEXT("%m:%s:%f")));

Will do the Trick ^^

I just saw your answer, yes, that is more succinct and works. I will use that.