endsWith

Summary

Checks if the string ends with the specified substring.

Usage

public bool endsWith(string substr)

Returns

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

Parameters

substr

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

Description

Checks if the string ends 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.endsWith("test")); // true
Console.log(str.endsWith("fog"));  // false
Case-insensitive endsWith
1
2
3
4
5
6
7
import System;
 
string sentence = "This is a test";
string substr = "Test";
Console.log(
    sentence.toLowerCase().endsWith(substr.toLowerCase())
);

Share

HTML | BBCode | Direct Link