"함수 startsWith()"의 두 판 사이의 차이

31번째 줄: 31번째 줄:
[[분류: JavaScript]]
[[분류: JavaScript]]
{{참고|자바스크립트 startsWith()}}
{{참고|자바스크립트 startsWith()}}
<syntaxhighlight lang='JavaScript'>
<syntaxhighlight lang='JavaScript' run>
var str = "Hello world!";
var str = "Hello world!";
console.log( str.startsWith("Hello") ); // true
 
console.log( str.startsWith("He") ); // true
// true
console.log( str.startsWith("ll") ); // false
console.log( str.startsWith("Hello") );
console.log( str.startsWith("ll", 2) ); // true
console.log( str.startsWith("He") );
console.log( str.startsWith("ll", 2) );
 
// false
console.log( str.startsWith("ll") );
</syntaxhighlight>
</syntaxhighlight>



2021년 12월 27일 (월) 14:18 판

1 개요

startsWith()
startswith()

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

var str = "Hello world!";

// true
console.log( str.startsWith("Hello") );
console.log( str.startsWith("He") );
console.log( str.startsWith("ll", 2) );

// false
console.log( str.startsWith("ll") );

4 Python

str = 'Hello world!'
print( str.startswith( 'Hello' ) ) # True
print( str.startswith( 'He' ) ) # True
print( str.startswith( 'll' ) ) # False
print( str.startswith( 'll', 2 ) ) # True
print( str.startswith( 'Hell', 0, 3 ) ) # False
print( str.startswith( 'Hell', 0, 4 ) ) # True

5 같이 보기

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