Betdon avatar

[c#] string(문자열)을 array(배열)로 잘라서 배치하는 방법

betdon

Published: 14 Sept 2018 › Updated: 14 Sept 2018[c#] string(문자열)을 array(배열)로 잘라서 배치하는 방법

[c#] string(문자열)을 array(배열)로 잘라서 배치하는 방법

string을 특정 조건에 맞춰서 잘라야할 때가 있습니다.
보통 저장했던걸 불러오거나 서버에서 받아온 string을 array로 전환하는데 사용됩니다.


public string str;
public string[] array;

를 준비합니다.

str = "a,b,c,d";
일 경우

array = str.Split(',');
를 실행해서 Split(char형의 조건)함수가 str을 잘라내면

array[0] = "a";
array[1] = "b";
array[2] = "c";
array[3] = "d";

의 결과가 도출됩니다.

잘라내는 기준은 char형태의 ','입니다.
잘라내는 조건이 string이 아니기 때문에 ","가 아닌 ','를 사용하시면 됩니다.
잘라내는 조건은 굳이 ','가 아니더라도 '/'나 'x'로도 가능합니다.
잘라내야할 원본 string의 양식에 맞춰서 조건을 부여해주면 됩니다.

array는 따로 new string으로 배열을 확보하지 않아도 Split()이 알아서 배열을 확장시킵니다.

Leave [c#] string(문자열)을 array(배열)로 잘라서 배치하는 방법 to:

Written by

GameDeveloper

Read more #kr-coding posts


Best Posts From Betdon

We have not curated any of betdon's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Betdon