Download

Why has my path string trailing chinese characters?

Hi,

Im usin the following code to read a text file into an FString:


FString ACustomController::ImportFromFile(FString AFilename)
{
    FString directory = FPaths::Combine(FPaths::GameContentDir(), "Data");
    FString result;

    return directory;   //  just testing  ...

    IPlatformFile& file = FPlatformFileManager::Get().GetPlatformFile();
    if (file.CreateDirectory(*directory)) {
        FString myFile = directory + "/" + AFilename;
        FFileHelper::LoadFileToString(result, *myFile);
    }
    return result;
}

When testing the code I foynd that weird folders with chinese characters were created within my content folder.
After just putting out the directory string, I see this:

StringOutput.jpg

Of course that explains the weird folder being created. But what is causing it and how to “sanitize” the string propertly?

What am I missing here?
Any help is appreciated :slight_smile:

Cheers,
Klaus

Be careful with string encoding on different platforms…



FPaths::Combine(FPaths::GameContentDir(), TEXT("Data") );


[USER=“434”]BrUnO XaVIeR[/USER]
Thanks :slight_smile: Works now as intended.

A little follow up question: If I now want to parse that string into an array with one line per array item using the FStringParseIntoArrayWS() function , it works, but also splits the string on space characters. For the standard version of ParseIntoArray() I need to supply a delimier literal. What delimiter symbol would I need to put in.
I tried TYEXT("
"), but that doesnt work…

It’s asking for a TCHAR.
For a tchar literal you can use



TEXT( '
' )