String to array

Jmnote (토론 | 기여)님의 2018년 8월 17일 (금) 23:04 판
string to array
string splits by every character
str_split()

1 Java

public class MyClass {
    public static void main(String args[]) {
        String str = "ABC안녕123★";
        char[] chs = str.toCharArray();
        for(int i=0; i<chs.length; i++) System.out.printf("%c, ",chs[i]);
        // A, B, C, 안, 녕, 1, 2, 3, ★, 
    }
}

2 JavaScript

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

3 Perl

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

4 PHP

<?php
function mb_str_split( $str ) { 
	return preg_split('/(?<!^)(?!$)/u', $str ); 
} 
$str = 'ABC안녕123★';
$chs = mb_str_split($str);
foreach($chs as $ch) echo "$ch, ";
# A, B, C, 안, 녕, 1, 2, 3, ★,

5 같이 보기

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