Download

FString Split incorrectly

I move the split string method from blueprint to c++. At blueprint it works correctly. Unluckily, the c++ the result is not correct. The right split string is empty, It should have the value at least.



void UWW::ExtractURL(const FText& text)

// url = https://maps.gsi.go.jp/#6/36.120129/140.097656/&base=std&ls=std
FString url = text.ToString();
FString zoomLevel = FString("");
FString latitude = FString("empty");
FString longitude = FString("");

url.Split(TEXT("#"), NULL, &zoomLevel);
GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Purple, FString::Printf(TEXT("Zoom + Lat #1: %s +] %s"), *zoomLevel, *latitude));
// Zoom + Lat #1: 6/36.120129/140.097656/ +] empty

zoomLevel.Split(TEXT("/"), &zoomLevel, &latitude);
GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Purple, FString::Printf(TEXT("Zoom + Lat #2: %s +] %s (bool) = %s"), *zoomLevel, *latitude));
// Zoom + Lat #1: 6 +] 
**// This Should be 6 +] 36.120129/140.097656/&base=std&ls=std**



I found the solution you must keep the value to temporal variable for next splitting or let say “do not use the left or right reference for next splitting” I don’t know the exactly reasons but this code below, it not works.



url.Split(TEXT("#"), NULL, &zoomLevel);
tmp = zoomLevel;
tmp.Split(TEXT("/"), &zoomLevel, &latitude);
tmp = latitude;
tmp.Split(TEXT("/"), &latitude, &longitude);
tmp = longitude;
tmp.Split(TEXT("/"), &longitude, &lang);
tmp = lang;
tmp.Split(TEXT("="), NULL, &lang);
tmp = lang;
tmp.Split(TEXT("&"), &lang, NULL);