# Convenience STRING manipulation Tutorial. ideal for beginners debugging

**URL:** <https://forums.unrealengine.com/t/convenience-string-manipulation-tutorial-ideal-for-beginners-debugging/10733>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [September 4, 2014, 10:18am UTC](https://forums.unrealengine.com/t/convenience-string-manipulation-tutorial-ideal-for-beginners-debugging/10733 "2014-09-04T10:18:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigolbear](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@bigolbear](https://forums.unrealengine.com/u/bigolbear)\
**Post date:** [September 4, 2014, 10:18am UTC](https://forums.unrealengine.com/t/convenience-string-manipulation-tutorial-ideal-for-beginners-debugging/10733/1 "2014-09-04T10:18:05Z")

</div>

After getting my self reaquainted with c++ I remembered just how much of a pain strings can be.

UE4 gives us FString, FName and FText to work with for various scenarios, and I recomend reading up on them,  
its important info for speed of calculation and localisation.  
Nonetheless the standard string (std::string) still has uses, especialy as a debugging tool.  
These files should allow you to work with strings in a manner similar to unreal script or other scripting languages.  
I wrote the following code to facilitate simple on screen debugging, and thought Id share it with the comunity.

Example uses:  
PrintStr(“some text about mouse X:” + ToString(MouseLocation.X) + " Y:" + ToString(MouseLocation.Y));

Add code to your project (select no base class) - name AdvString  
in order to use GEngine you need to include Engine.h in your main project file, Projects created in later versions only include Engineminimal.h

header

```auto

// File: AdvString.h
#include <iostream>
#include <sstream>
#include <string>
#include <stdexcept>
#include "YOUR MAIN CLASS.h"

class BadConversion : public std::runtime_error {
public:
	BadConversion(std::string const& s)
		: std::runtime_error(s)
	{ }
};

inline std::string ToString(double x)
{
	std::ostringstream o;
	if (!(o << x))
		throw BadConversion("ToString(double)");
	return o.str();
}

inline std::string ToString(float x)
{
	std::ostringstream o;
	if (!(o << x))
		throw BadConversion("ToString(float)");
	return o.str();
}

inline std::string ToString(int x)
{
	std::ostringstream o;
	if (!(o << x))
		throw BadConversion("ToString(int)");
	return o.str();
}

inline std::string ToString(short x)
{
	std::ostringstream o;
	if (!(o << x))
		throw BadConversion("ToString(short)");
	return o.str();
}

inline std::string ToString(long x)
{
	std::ostringstream o;
	if (!(o << x))
		throw BadConversion("ToString(long)");
	return o.str();
}

inline std::string ToString(bool x)
{
	std::ostringstream o;
	if (!(o << x))
		throw BadConversion("ToString(double)");
	return o.str();
}

inline FString ToFString(std::string x)
{
	FString f(x.c_str());
	return f;
}

inline void PrintFStr(FString text)
{
	GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::White, text);
}

inline void PrintFStrRed(FString text)
{
	GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::Red, text);
}

inline void PrintFStrGreen(FString text)
{
	GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::Green, text);
}

inline void PrintFStrBlue(FString text)
{
	GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::Blue, text);
}

inline void PrintStr(std::string text)
{
	GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::White, ToFString(text));
}

inline void PrintStrRed(std::string text)
{
	GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::Red, ToFString(text));
}

inline void PrintStrGreen(std::string text)
{
	GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::Green, ToFString(text));
}

inline void PrintStrBlue(std::string text)
{
	GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::Blue, ToFString(text));
} 

```

source

```auto

#include "YOUR MAIN CLASS.h"
#include "AdvString.h"

// inline code defined in .h

```

Enjoy.

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [September 5, 2014, 5:21am UTC](https://forums.unrealengine.com/t/convenience-string-manipulation-tutorial-ideal-for-beginners-debugging/10733/2 "2014-09-05T05:21:58Z")

</div>

Very nice sharing!

You should make this into a wiki so people can always find it!

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

Rama

---

<div class="post-metadata">

**Author:** ![bigolbear](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@bigolbear](https://forums.unrealengine.com/u/bigolbear)\
**Post date:** [September 5, 2014, 4:46pm UTC](https://forums.unrealengine.com/t/convenience-string-manipulation-tutorial-ideal-for-beginners-debugging/10733/3 "2014-09-05T16:46:43Z")

</div>

Done, thanks for the sugestion.
