___|  _ \   |  |    |   |_ _|\ \     / ____|
 |     |   |  |  |    |   |  |  \ \   /  __|
 |   | |   | ___ __|  ___ |  |   \ \ /   |
\____|\___/     _|   _|  _|___|   \_/   _____| 

 --- A GOPHER-LIKE INTERFACE FOR HIVE BLOCKCHAIN ---

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

BY: @betdon | CREATED: Sept. 14, 2018, 6:12 a.m. | VOTES: 18 | PAYOUT: $0.00 | [ VOTE ]

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()이 알아서 배열을 확장시킵니다.

TAGS: [ #kr-coding ] [ #coding ] [ #unity ]

Replies

@steemitboard | May 15, 2019, 5:07 p.m. | Votes: 0 | [ VOTE ]

Congratulations @betdon! You received a personal award!

https://steemitimages.com/70x70/http://steemitboard.com/@betdon/birthday2.pngHappy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

New japanese speaking community Steem Meetup badge

Vote for @Steemitboard as a witness to get one more award and increased upvotes!
[ BACK TO TRENDING ] [ BACK TO MENU ]
CMD>