티스토리 뷰
String.Concat
문자열을 연결하는 함수
String의 인스턴스를 하나 이상 연결하거나 String의 인스턴스 값에 해당하는 Object 표현을 하나 이상 연결하는 함수이다.
네임스페이스 |
System | |
어셈블리 | System.Runtime.dll | |
함수명 | String.Concat | 지정된 문자열 또는 유니코드 문자 배열의 요소로 구분된 이 인스턴스의 부분 문자열이 포함된 문자열 배열을 반환 |
오버로드 |
Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>) | 지정된 네 개의 읽기 전용 문자 범위의 문자열 표현을 연결 |
Concat(String, String, String, String) | 지정된 네 개의 문자열을 연결 | |
Concat(ReadOnlySpan, ReadOnlySpan, ReadOnlySpan) | 지정된 세 개의 읽기 전용 문자 범위의 문자열 표현을 연결 | |
Concat(String, String) | 지정된 두 개의 문자열을 연결 | |
Concat(String, String, String) | 지정된 세 개의 문자열을 연결 | |
Concat(Object, Object) | 지정된 두 개의 오브젝트를 연결하는 함수 | |
Concat(String[]) | 문자열 배열을 연결하는 함수 | |
Concat(Object[]) | 오브젝트 배열을 연결하는 함수 | |
Concat(Object) | 지정된 오브젝트를 문자열 표현으로 만든다. | |
Concat(IEnumerable) | IEnumerable<T> 형식의 생성된 String 컬렉션의 멤버를 연결 | |
Concat(ReadOnlySpan, ReadOnlySpan) | 지정된 2 개의 읽기 전용 문자 범위의 문자열 표현을 연결 | |
Concat<T>(IEnumerable<T>) | IEnumerable<T> 구현의 멤버를 연결 | |
매개변수 |
구분 문자 | 문자열 분할에 사용되는 분할 지점을 정하는 문자 값 |
구분 문자 배열 | 문자열 배열에 포함된 모든 문자를 분할 지점으로 정하는 값 | |
옵션 (StringSplitOptions) | 문자열 분할에 사용될 옵션 값 | |
최대 개수 | 분할할 수 있는 최대 개수 제한 값 | |
반환값 | String |
Concat(Object, Object, Object)
Object를 사용할때는 받은 객체를 문자열로 형변환한다.
함수명 | Concat(Object, Object, Object) | |
매개변수 | Object | 첫 번째 오브젝트 |
Object | 두 번째 오브젝트 | |
Object | 세 번째 오브젝트 |
using System;
class stringConcat5 {
public static void Main() {
int i = -123;
Object o = i;
Object[] objs = new Object[] {-123, -456, -789};
Console.WriteLine("Concatenate 1, 2, and 3 objects:");
Console.WriteLine("1) {0}", String.Concat(o));
Console.WriteLine("2) {0}", String.Concat(o, o));
Console.WriteLine("3) {0}", String.Concat(o, o, o));
Console.WriteLine("\nConcatenate 4 objects and a variable length parameter list:");
Console.WriteLine("4) {0}", String.Concat(o, o, o, o));
Console.WriteLine("5) {0}", String.Concat(o, o, o, o, o));
Console.WriteLine("\nConcatenate a 3-element object array:");
Console.WriteLine("6) {0}", String.Concat(objs));
}
}
// The example displays the following output:
// Concatenate 1, 2, and 3 objects:
// 1) -123
// 2) -123-123
// 3) -123-123-123
//
// Concatenate 4 objects and a variable length parameter list:
// 4) -123-123-123-123
// 5) -123-123-123-123-123
//
// Concatenate a 3-element object array:
// 6) -123-456-789
Concat(IEnumerable<String>)
함수명 | Concat(Object, Object, Object) | |
매개변수 | IEnumerable<String> | List, Stack, Queue와 같은 컬렉션에 반복이 필요한 경우 사용되는 인터페이스 |
using System;
using System.Collections.Generic;
public class Example
{
public static void Main()
{
int maxPrime = 100;
IEnumerable<String> primeList = GetPrimes(maxPrime);
Console.WriteLine("Primes less than {0}:", maxPrime);
Console.WriteLine(" {0}", String.Concat(primeList));
}
private static IEnumerable<String> GetPrimes(int maxPrime)
{
Array values = Array.CreateInstance(typeof(int),
new int[] { maxPrime - 1}, new int[] { 2 });
// Use Sieve of Erathsthenes to determine prime numbers.
for (int ctr = values.GetLowerBound(0); ctr <= (int) Math.Ceiling(Math.Sqrt(values.GetUpperBound(0))); ctr++)
{
if ((int) values.GetValue(ctr) == 1) continue;
for (int multiplier = ctr; multiplier <= maxPrime / 2; multiplier++)
if (ctr * multiplier <= maxPrime)
values.SetValue(1, ctr * multiplier);
}
List<String> primes = new List<String>();
for (int ctr = values.GetLowerBound(0); ctr <= values.GetUpperBound(0); ctr++)
if ((int) values.GetValue(ctr) == 0)
primes.Add(ctr.ToString() + " ");
return primes;
}
}
// The example displays the following output:
// Primes less than 100:
// 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
Concat<T>(IEnumerable<T>)
함수명 | Concat<T>(IEnumerable<T>) | |
매개변수 | IEnumerable<T> | List, Stack, Queue와 같은 컬렉션에 반복이 필요한 경우 사용되는 인터페이스 |
using System;
using System.Collections.Generic;
using System.Linq;
public class Animal
{
public string Kind;
public string Order;
public Animal(string kind, string order)
{
this.Kind = kind;
this.Order = order;
}
public override string ToString()
{
return this.Kind;
}
}
public class Example
{
public static void Main()
{
List<Animal> animals = new List<Animal>();
animals.Add(new Animal("Squirrel", "Rodent"));
animals.Add(new Animal("Gray Wolf", "Carnivora"));
animals.Add(new Animal("Capybara", "Rodent"));
string output = String.Concat(animals.Where( animal =>
(animal.Order == "Rodent")));
Console.WriteLine(output);
}
}
// The example displays the following output:
// SquirrelCapybara
예제코드
예제코드
- 예제 코드 동작 설명
참고자료
'Computer Language > C#' 카테고리의 다른 글
[C#] String.Insert(Int32, String) 메서드 (0) | 2023.08.14 |
---|---|
[C#] String.Trim 메서드 - 공백제거 (0) | 2023.08.14 |
[C#] String.Split 메서드 - 문자열 분할 (0) | 2023.08.13 |
[C#] 문자열 자르기 (Substring, Split, Index, Remove, Regex) (0) | 2023.08.11 |
[C#] 문자열을 리스트/배열로 전환 (string to int list/array) (0) | 2023.08.09 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 구조
- 알고리즘
- 클래스
- 스레드
- const
- 함수
- 메모리
- thread
- 크기
- 인터럽트
- 컴파일
- 상속
- 운영체제
- 멀티스레드
- 포인터
- 수학
- dynamic_cast
- 초기화
- New
- CPU
- 백준
- 할당
- static_cast
- malloc
- 게임수학
- 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 |
글 보관함