Help with FString::RemoveAt()

Hi,

I’m attempting to ignore the first character in an FString that I am printing to the screen using RemoveAt(0,1,true). My code snippet


					// Parse data here
					FString ReceivedString = StringFromBinaryArray(ReceivedData); // StringFromBinaryArray function returning FString with input ReceivedData

					GEngine->AddOnScreenDebugMessage(0, 30.f, FColor::Black, FString::Printf(TEXT("Y Location: %s"), *ReceivedString));

					FString PosString = ReceivedString.RemoveAt(0, 1, true);
					GEngine->AddOnScreenDebugMessage(0, 30.f, FColor::Black, FString::Printf(TEXT("Y Location: %s"), PosString));

And Intellisense returns the error: “No suitable constructor exists to convert from ‘void’ to ‘FString’” with the red line underneath ReceivedString.RemoveAt. Any ideas on what I should do differently?

Hi, first think I suggest doing, get rid of GEngine->AddOnScreenDebugMessage, and use instead UE_LOG() A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums

I was experiencing a bunch of crashes and weird behavior when trying to run standalone without the editor.

The problem is with the function RemoveAt(). It returns a void. IE, it does the change to ReceivedString, without outputing anything.

So, you you either make a copy of ReceivedString into PosString, and then just PosString.RemoveAt(0, 1, true).

Also, your code could crash at the PrintF, as you are not using the *PosString, and only have PosString.

Ah, I see now. I didn’t realize that RemoveAt() was what was returning void. Okay so I changed it to



					FString ReceivedString = StringFromBinaryArray(ReceivedData); // StringFromBinaryArray function returning FString with input ReceivedData

					GEngine->AddOnScreenDebugMessage(0, 30.f, FColor::Black, FString::Printf(TEXT("Y Location: %s"), *ReceivedString));

					FString PosString = ReceivedString;
					PosString.RemoveAt(0, 1, true);

					GEngine->AddOnScreenDebugMessage(0, 30.f, FColor::Black, FString::Printf(TEXT("Y Location: %s"), *PosString));

No errors from intellisense! Now to see if it compiles and works. Thanks! If it doesn’t I will look more into UE_LOG and see if that fixes any issues.

Edit: It works!

Glad it works.

About AddOnScreenDebugMessage(), it’s fine when you are in editor, but when you run stand alone it may crash, and you end up doing “if (GEngine() != nullpointer) {//run code}” and it just gets messy fast.

Huh, good to know. I haven’t actually created a standalone game yet so I haven’t run into that yet.