Here, we will create a string and then we will check the string starts with a specified substring using the startsWith() method. The startsWith() method returns Boolean value. It returns true if the string starts with a specified substring. Otherwise, it will return false.
Program/Source Code:
The source code to check the string starts with a specified substring is given below. The given program is compiled and executed on the ubuntu 18.04 operating system successfully.
Output:
In the above program, we used an object-oriented approach to create the program. And, we created an object Sample. Here, we defined main() function. The main() function is the entry point for the program.
In the main() function, we created two string variables str1, str2. Both strings are initialized with "Hello World". Then we check strings starts with specified substring using startswith() method and print the appropriate message on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer