startsWith method code example
Example 1: javascript string starts with
function startsWith(str, word) {
return str.lastIndexOf(word, 0) === 0;
}
startsWith("Welcome to earth.","Welcome");
Example 2: how to check string start with #
public class JavaExample{
public static void main(String args[]){
String s = " This is just a sample string";
System.out.println(s.startsWith("This"));
System.out.println(s.startsWith("Hi"));
}
}
Example 3: java string contains at beginning
public class StringExample
{
public static void main(String[] args)
{
String blogName = "howtodoinjava.com";
System.out.println( blogName.startsWith("how") );
System.out.println( "howtodoinjava.com".startsWith("howto") );
System.out.println( "howtodoinjava.com".startsWith("hello") );
}
}