User Tools

Site Tools


en:examples:objects:concatenating_two_strings

Concatenating two orxSTRINGs

#include "orx.h"
#ifdef __orxMSVC__ 
	#include "malloc.h"
#endif
 
...
 
const orxSTRING stringOne = "I like the beach. ";
const orxSTRING stringTwo = "And I like the waves.";
 
int length = orxString_GetLength(stringOne) + orxString_GetLength(stringTwo) + 1;
#ifdef __orxMSVC__ 
	orxCHAR *concatenatedString = (orxCHAR *)alloca(length * sizeof(orxCHAR));
#else /* __orxMSVC__ */ 
	orxCHAR concatenatedString[length] = {};
#endif /* __orxMSVC__ */
 
orxString_NPrint(concatenatedString, length * sizeof(orxCHAR), "%s%s", stringOne, stringTwo);
 
orxLOG("Your string is %s", concatenatedString);

Because the example is using a Variable Length Array in C, Visual Studio's compiler doesn't support this. Provision has to be made for that compiler. Read more about it here.

en/examples/objects/concatenating_two_strings.txt · Last modified: 2023/03/28 21:14 (16 months ago) by iarwain