User Tools

Site Tools


tutorials:community:sausage:orxstrings_strings_and_chars

orxSTRINGs, strings and chars

Orx has orxSTRINGs and a nice bunch of functions for performing all sorts of string tricks. Lots of orx functions require an orxSTRING type as a parameter, and so it's important to know how to get other string types like char arrays and STL strings (std::string) into orxSTRING format.

char[] to orxSTRING

	char someCharArray[] = "Honey Bees";
 
	orxSTRING anOrxString = someCharArray;

std::string to orxSTRING

	std::string pieceOfString = "Honey Bees";
 
	orxSTRING anOrxString = (orxCHAR*)pieceOfString.c_str();

std::stringstream to orxSTRING

	std::stringstream aStringStream;
	aStringStream << "Letters " << 1 << " and numbers " << 999;
	std::string pieceOfString = aStringStream.str();
 
	orxSTRING anOrxString = (orxCHAR*)pieceOfString.c_str();

orxSTRING to std::string

	const orxSTRING orxStr = orxObject_GetName(someObject);
 
	std::string pieceOfString = orxStr;

Conversion isn't always necessary, but sometimes you do need to. So this is a handy reference to keep around.

tutorials/community/sausage/orxstrings_strings_and_chars.txt · Last modified: 2017/05/30 05:50 (8 weeks ago) (external edit)