I’m trying to convert a String to an Array so that I can use a binary search to see if characters are repeating. I’m fluent in Java but new to C++. My thinking is this: I’m creating an array of FString so that I can assign the result of .GetCharArray() to it, but it throws an error implying that I’m using the wrong data type. Could use some help here.
bool UBullCowCartridge::CheckInput(FString Input) {
bool bResult = false;
int32 size = Input.Len();
char* chars = new char[size];
//Convert string to char
FString* word = new FString[size];
word = Input.GetCharArray();
//Check if previous characters are already present
//Delete the collection
delete[] chars;
return bResult;
}
There no need for conversion, FString is already is (contained) array of TCHARs (as C and C++ don’t have native support for strings other then literal string, everything is converted to array of chars, thats how low level C++ is) and you can operate it same as array with [] operator and C++11 for each loops. And because of that with GetCharArray() you not actually converting… you getting reference to TArray of TCHARs that FString actually use to hold TCHAR data, as DataType typedef decleres:
typedef TArray<TCHAR> DataType;
I guess point of this typedef is to make potential type transition easier or multiplatfrom support for it.
But again there no need for that you can already do a lot just by accessing FString like array
You should also avoid using native arrays with UE4 APIs or else it explicitly using them (and engine will use pointer in that case instead of reference), as UE4 engine code expect you to use TArray all the time. You can always access native array via this function (ofcorse direcly writing anything to it is bad idea):
But that DataType indeed be confusing