"String to array"의 두 판 사이의 차이

16번째 줄: 16번째 줄:
[[분류: Perl]]
[[분류: Perl]]
<source lang='perl'>
<source lang='perl'>
use utf8;
@query=split '', 'ABC안녕123★';
@query=split '', 'ABC안녕123★';
print "$_\n" for @query;
print "$_, " for @query;
#A
# A, B, C, , , 1, 2, 3, ,
#B
#C
#
#
#1
#2
#3
#
</source>
</source>



2018년 8월 17일 (금) 22:00 판

string to array
str_split()

1 JavaScript

var chars = 'ABC안녕123★'.split('');
console.log( chars );
// ["A", "B", "C", "안", "녕", "1", "2", "3", "★"]

2 Perl

use utf8;
@query=split '', 'ABC안녕123★';
print "$_, " for @query;
# A, B, C, 안, 녕, 1, 2, 3, ★,

3 PHP

function mb_str_split( $str ) { 
	return preg_split('/(?<!^)(?!$)/u', $str ); 
} 

$str = 'ABC안녕123★';
$arr = mb_str_split($str);
print_r($arr);
# Array
# (
#     [0] => A
#     [1] => B
#     [2] => C
#     [3] => 안
#     [4] => 녕
#     [5] => 1
#     [6] => 2
#     [7] => 3
#     [8] => ★
# )

4 같이 보기

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