startsWith

Summary

Checks if the string begins with the specified substring.

Usage

public bool startsWith(string substr)

Returns

true if the string begins with the specified substring and false otherwise.

Parameters

substr

The substring to check for at the beginning of the string.

Description

Checks if the string begins with the specified substring.

This method is case-sensitive.

Examples

Basic Usage
1
2
3
4
5
import System;
 
string str = "This is a test";
Console.log(str.startsWith("This")); // true
Console.log(str.startsWith("fog"));  // false
Case-insensitive startsWith
1
2
3
4
5
6
7
import System;
 
string sentence = "This is a test.";
string substr = "this";
Console.log(
    sentence.toLowerCase().startsWith(substr.toLowerCase())
);

Share

HTML | BBCode | Direct Link