함수 startsWith()

1 개요[ | ]

startsWith()
startswith()
HasPrefix()
str_starts_with()

2 Go[ | ]

package main

import (
	"fmt"
	"strings"
)

func main() {
	str := "Hello world!"

	// true
	fmt.Println(strings.HasPrefix(str, "Hello"))
	fmt.Println(strings.HasPrefix(str, "He"))
	fmt.Println(strings.HasPrefix(str[2:], "ll"))

	// false
	fmt.Println(strings.HasPrefix(str, "ll"))
}

3 JavaScript[ | ]

const str = "Hello world!";
console.log( str.startsWith("Hello") ); // true
console.log( str.startsWith("He") ); // true
console.log( str.startsWith("ll", 2) ); // true
console.log( str.startsWith("ll") ); // false

4 PHP[ | ]

<?php
$str = 'To be, or not to be, that is the question.';
var_dump(str_starts_with($str, 'To be'));
var_dump(str_starts_with($str, 'not to be'));

5 Python[ | ]

str = 'Hello world!'

# True
print( str.startswith( 'Hello' ) )
print( str.startswith( 'He' ) )
print( str.startswith( 'll', 2 ) )
print( str.startswith( 'Hell', 0, 4 ) )

# False
print( str.startswith( 'll' ) )
print( str.startswith( 'Hell', 0, 3 ) )

6 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}