Function: StrEndsWith
Function: StrEndsWith

Function: StrEndsWith

StrEndsWith ( STRING, SUBSTRING )

Checks if a string ends with another string.

Parameters

Parameter Type Description
STRING VALUE(STRING) The string to search in.
SUBSTRING VALUE(STRING) The substring to test for.

Returns

VALUE(BOOLEAN) TRUE if the first string ends with the second string, FALSE otherwise.

What It Does

This function returns TRUE if the first string ends with the second string, or FALSE if not. Both provided values are interpreted as strings before the check. The check is case-sensitive.


	a = strEndsWith("applesauce", "sauce");    // a = true
	a = strEndsWith("banana", "na");           // a = true
	a = strEndsWith("tomato", "to");           // a = true
	a = strEndsWith("applesauce", "apple");    // a = false
	a = strEndsWith(12345, 1);                 // a = false (converted to strings)
	a = strEndsWith(12345, 5);                 // a = true (converted to strings)
	a = strEndsWith("ABCDEFG", "g");           // a = false (case-sensitive)

Example

String Searching Examples


world
{
	start()
	{
		// Index Search
		textln(strIndex("Apples and Oranges", "Apples"));		// 0
		textln(strIndex("Apples and Oranges", "Pears"));		// -1
		textln("");

		// Index vs. LastIndex
		textln(strIndex("Apples and Oranges", "an"));			// 7 
		textln(strLastIndex("Apples and Oranges", "an"));		// 13
		textln(strIndex("Apples and Oranges", "es"));			// 4 
		textln(strLastIndex("Apples and Oranges", "es"));		// 16
		textln("");

		// Contains
		textln(strContains("Apples and Oranges", "Apples"));	// true 
		textln(strContains("Apples and Oranges", "apples"));	// false 
		textln(strContains("Apples and Oranges", "Pears"));		// false
		textln(strContains(1234, 23));							// true (numbers are converted to strings)
		textln(strContains(0.56, "."));							// true (numbers are converted to strings)
		textln("");

		// Starts With
		textln(strStartsWith("Apples and Oranges", "Apples"));	// true
		textln(strStartsWith("Apples and Oranges", "apples"));	// false (case sensitive)
		textln(strStartsWith("Apples and Oranges", "C"));		// false
		textln(strStartsWith(123456, 123));						// true (numbers are converted to strings)
		textln(strStartsWith(5 + 5, "1"));						// true (numbers are converted to strings)
		textln("");

		// Ends With
		textln(strEndsWith("Apples and Oranges", "Oranges"));	// true
		textln(strEndsWith("Apples and Oranges", "oranges"));	// false (case sensitive)
		textln(strEndsWith("Apples and Oranges", "z"));			// false
		textln(strEndsWith(123456, 456));						// true (numbers are converted to strings)
		textln(strEndsWith(-1.4, ".4"));						// true (numbers are converted to strings)

		quit;
	}
}
×

Modal Header