■ 문자열을 연결하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
using System.Collections.Generic; using System.Text; #region 문자열 연결하기 - JoinString(sourceList, separator) /// <summary> /// 문자열 연결하기 /// </summary> /// <param name="sourceList">소스 리스트</param> /// <param name="separator">분리자</param> /// <returns>문자열</returns> public string JoinString(List<string> sourceList, string separator) { if(sourceList == null || sourceList.Count == 0) { return string.Empty; } if(sourceList.Count > 10000) { StringBuilder stringBuilder = new StringBuilder(); for(int i = 0; i < sourceList.Count; i++) { stringBuilder.Append(sourceList[i]); if(i != sourceList.Count - 1) { stringBuilder.Append(separator); } } return stringBuilder.ToString(); } else { return string.Join(separator, sourceList); } } #endregion |