Hi all,
I have a TMap which I am constructing using a FString Key and a Struct for the Value (this struct is just 2 FStrings) from a XML parsed file.
I am parsing the XML file correctly and populating the TMap with the data, but I am having problems finding the ‘key’ with the TMap after construction. Here is my code so far…
const FXmlFile file(L"D:/file.xml");
const FXmlNode* SceneNode = file.GetRootNode();
FString scenename = SceneNode->GetTag();
// Get all child nodes
TArray<FXmlNode*> nodes = SceneNode->GetChildrenNodes();
TMap<FString, FLanguageData*> LanguageLocalised;
// Create TMap
for (int i = 0; i < nodes.Num(); ++i)
{
if (nodes[i]->GetTag() == "textid")
{
FString english = nodes[i + 1]->GetContent();
FString french = nodes[i + 2]->GetContent();
// Create our Language Struct and add it to the Map file
FLanguageData* value = new FLanguageData();
value->English = english;
value->French = french;
FString key = nodes[i]->GetContent();
LanguageLocalised.Add(key, value);
}
}
// Contains
bool contains = LanguageLocalised.Contains("key1");
if (contains == true)
{
UE_LOG(LogTemp, Warning, TEXT("TRUE"));
}
else
{
UE_LOG(LogTemp, Warning, TEXT("FALSE"));
}
// Loop through Map
for (auto& KVP : LanguageLocalised)
{
FString Key = KVP.Key;
FLanguageData* ld = KVP.Value;
UE_LOG(LogTemp, Warning, TEXT("Search for keys: %s"), *Key);
UE_LOG(LogTemp, Warning, TEXT("Search for value: %s"), *ld->English);
}
My basic aim is to output the data from the corresponding key value, “key1”. You can see from my OutputLog (see image below) that the contains if state is returning FALSE. You can also see from this log that ‘key1’ is in the TMap (see Loop through Map in code snippet).
If I hardcode an additional entry into the TMap I can find it with a ‘contains’ just fine, so I’m guessing it’s related to my ‘FString key = nodes[i]->GetContent();’.
As I’m passing in a ‘hardcoded’ string into TMap.Contains(“key1”) or TMap.Contains(TEXT(“key1”)), and this is being compared against the original stored key string which came from a pointer: nodes[i]->GetContent(); (XmlParser), would this be why the comparison is failing?
My knowledge of c++ is one of learning, so any help would be greatly received.
Best regards,
Matt.