Function: StrStartsWith
Function: StrStartsWith

Function: StrStartsWith

StrStartsWith ( STRING, SUBSTRING )

Checks if a string starts 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 starts with the second string, FALSE otherwise.

What It Does

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


	a = strStartsWith("applesauce", "apple");   // a = true
	a = strStartsWith("banana", "ba");          // a = true
	a = strStartsWith("tomato", "to");          // a = true
	a = strStartsWith("applesauce", "sauce");   // a = false
	a = strStartsWith(12345, 1);                // a = true  (converted to strings)
	a = strStartsWith(12345, 5);                // a = false (converted to strings)
	a = strStartsWith("ABCDEFG", "a");          // 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