Jive reference manual
String.cpp
/************************************************************************
*
* This example demonstrates how to use the String class
*
***********************************************************************/
#include <jem/base/System.h>
#include <jem/base/String.h>
#include <jem/base/CString.h>
using namespace jem;
using namespace jem::io;
//-----------------------------------------------------------------------
// run
//-----------------------------------------------------------------------
int run ()
{
Writer& out = System::out ();
String s1 = " Hello I am a string ";
String s2 = s1.stripWhite ();
String s3 = "somebody";
String s4 = "a";
idx_t i;
out << endl;
out << s1 << endl << endl;
out << s2 << endl << endl;
out << s1[slice(2,13)] + s3.toUpper() << endl << endl;
i = s1.rfind ( s4 );
if ( i >= 0 )
{
out << s1[slice(i,END)] << endl << endl;
}
else
{
out << "substring " + s4 + " cannot be found"
<< endl << endl;
}
i = s1.find ( s4 );
if ( i >= 0 )
{
out << s1[slice(i,END)] << endl << endl;
}
else
{
out << "substring \"" + s4 + "\" cannot be found"
<< endl << endl;
}
out << String::format ( "integer : %d\n"
"float : %g\n"
"pointer : %p\n",
i,
1.2,
&s1 )
<< endl;
return 0;
}
//-----------------------------------------------------------------------
// main
//-----------------------------------------------------------------------
int main ()
{
return System::exec ( & run );
}