substring of a string code example

Example 1: substring

const str = 'Mozilla';

console.log(str.substring(1, 3));
// expected output: "oz"

console.log(str.substring(2));
// expected output: "zilla"

Example 2: how to do substring java

class Main {
  public static void main (String[] args) {
    
    String str = "Hello World!";
    
    String firstWord = str.substring(0, 5);
    //two parameters are start and end index: (inclusive, non-inclusive)
    
    String secondWord = str.substring(6, 11);
    
    //firstWord has string "Hello"
    //secondWord has string "World"
  }
}

Example 3: str.substring if 2 letters

public String firstTwo(String str) {
    return str.length() < 2 ? str : str.substring(0, 2);
}

Example 4: substring

# Python3 program to Remove repeated 
# unordered sublists from list
  
def Remove(lst):
     return ([list(i) for i in {*[tuple(sorted(i)) for i in lst]}])  
       
# Driver code
lst = [[1], [1, 2], [3, 4, 5], [2, 1]]
print(Remove(lst))