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

잔글 (Jmnote 사용자가 함수 substr after 문서를 함수 substr after() 문서로 옮겼습니다)
 
(사용자 2명의 중간 판 3개는 보이지 않습니다)
1번째 줄: 1번째 줄:
[[category: String]]
[[category: String]]
==Bash==
[[category: Bash]]
<syntaxhighlight lang='bash'>
str='hello world'
echo ${str#*ll}
# o world
echo ${str#*l}
# lo world
echo ${str#*x}
# hello world
</syntaxhighlight>
==Go==
[[분류: Go]]
{{참고|Go substrAfter()}}
<syntaxhighlight lang='go' run>
package main
import (
"fmt"
"strings"
)
func substrAfter(haystack string, needle string) string {
pos := strings.Index(haystack, needle)
if pos == -1 {
return ""
}
return haystack[pos+len(needle):]
}
func main() {
fmt.Println(substrAfter("hello world", "l"))  // lo world
fmt.Println(substrAfter("hello world", "ll")) // o world
fmt.Println(substrAfter("hello world", "x"))  //
}
</syntaxhighlight>


==PHP==
==PHP==
[[category: PHP]]
[[category: PHP]]
<source lang='PHP'>
{{참고|PHP substr_after()}}
<syntaxhighlight lang='PHP'>
function substr_after($needle, $haystack) { return substr( strchr($haystack,$needle), strlen($needle) ); }
function substr_after($needle, $haystack) { return substr( strchr($haystack,$needle), strlen($needle) ); }


12번째 줄: 50번째 줄:
# lo world
# lo world
#
#
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2022년 5월 19일 (목) 14:10 기준 최신판


1 Bash[ | ]

str='hello world'
echo ${str#*ll}
# o world
echo ${str#*l}
# lo world
echo ${str#*x}
# hello world

2 Go[ | ]

package main

import (
	"fmt"
	"strings"
)

func substrAfter(haystack string, needle string) string {
	pos := strings.Index(haystack, needle)
	if pos == -1 {
		return ""
	}
	return haystack[pos+len(needle):]
}
func main() {
	fmt.Println(substrAfter("hello world", "l"))  // lo world
	fmt.Println(substrAfter("hello world", "ll")) // o world
	fmt.Println(substrAfter("hello world", "x"))  //
}

3 PHP[ | ]

function substr_after($needle, $haystack) { return substr( strchr($haystack,$needle), strlen($needle) ); }

echo substr_after('ll', 'hello world');
echo substr_after('l', 'hello world');
echo substr_after('x', 'hello world'); // bool(false)
# o world
# lo world
#

4 같이 보기[ | ]

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