Function: StrTrim
Function: StrTrim

Function: StrTrim

StrTrim ( STRING )

Removes the whitespace from the beginning and end of a string and returns the resulting string.

Parameters

Parameter Type Description
STRING VALUE(STRING) The input string.

Returns

VALUE(STRING) A new string with the whitespace removed from the beginning and end.

What It Does

This removes the whitespace from the beginning and end of a string and returns the resulting string. Whitespace is commonly spaces, tabs, or newlines, but can be a range of non-visible characters, depending on implementation. The provided value is interpreted as a string before trim.


	a = strTrim("    apple      ");   // a = "apple"
	a = strTrim("\tapple");           // a = "apple"
	a = strTrim("apple");             // a = "apple"
	a = strTrim("apples and pears");  // a = "apples and pears"

Example

String Manipulation Examples


world
{
	start()
	{
		// Concatenation
		textln("to" + "gether");                                // "together" 
		textln(strConcat("to", "gether"));                      // "together" 
		textln(strConcat(strConcat("to", "gether"), "ness"));	// "togetherness"
		textln(4 + 5);											// 9
		textln(strConcat(4, 5));								// "45" (both values are converted to strings first)
		textln("");

		// Substring
		textln(substring("applejack", 0, 5));		// "apple" 
		textln(substring("applejack", 5, 9));		// "jack" 
		textln(substring("applejack", 9, 5));		// "" 
		textln(substring("applejack", -3, 100));	// "applejack" = substring("applejack", 0, 9)
		textln(substring(123, 0, 1));				// "1" (first value is converted to a string first)
		textln("");

		// Lower-case convert.
		textln(strLower("Apples and Oranges"));		// "apples and oranges"
		textln(strLower("HELLO!!!"));				// "hello!!!"
		textln(strLower("123456789"));				// "123456789"
		textln("");
		
		// Upper-case convert.
		textln(strUpper("Apples and Oranges"));		// "APPLES AND ORANGES"
		textln(strUpper("hey."));					// "HEY."
		textln(strUpper("123456789"));				// "123456789"
		textln("");

		// Get single character.
		textln(strChar("Apples and Oranges", 0));	// "A"
		textln(strChar("This is a string.", 5));	// "i"
		textln(strChar(12345, 2));					// "3" (converted to string first)
		textln(strChar("apple", -1));				// "" (out of range)
		textln("");

		// string trim.
		textln(strTrim("      apple"));				// "apple"
		textln(strTrim("apple      "));				// "apple"
		textln(strTrim("   apple   "));				// "apple"
		textln(strTrim("\tapple\t"));				// "apple"
						 
		quit;
	}
}

Additional Technical Notes

Whitespace, as defined by TAME, is all non-visible characters less than or equal to Unicode 0x0020 (ASCII space), which is the space character plus all ASCII control codes (tabs, line feeds, etc.). While some Shells may render these characters with special symbols on output (like in Windows/DOS terminals), this does not mean that they are treated as non-whitespace in the engine.

Some implementations may define "whitespace" to include the extended Unicode spacing characters, but this has not been standardized across TAME implementations yet.

×

Modal Header