String.Concat 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
오버로드
설명
참고
C# 및 F#과 같은 +
언어의 문자열 연결 연산자 또는 &
+
Visual Basic에서 문자열을 연결할 수도 있습니다. 두 컴파일러 모두 연결 연산자를 의 String.Concat
오버로드 중 하나에 대한 호출로 변환합니다.
Concat(String, String, String, String)
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
String의 지정된 네 인스턴스를 연결합니다.
public:
static System::String ^ Concat(System::String ^ str0, System::String ^ str1, System::String ^ str2, System::String ^ str3);
public static string Concat (string str0, string str1, string str2, string str3);
public static string Concat (string? str0, string? str1, string? str2, string? str3);
static member Concat : string * string * string * string -> string
Public Shared Function Concat (str0 As String, str1 As String, str2 As String, str3 As String) As String
매개 변수
- str0
- String
연결할 첫 번째 문자열입니다.
- str1
- String
연결할 두 번째 문자열입니다.
- str2
- String
연결할 세 번째 문자열입니다.
- str3
- String
연결할 네 번째 문자열입니다.
반환
연결된 str0
, str1
, str2
및 str3
를 반환합니다.
예제
다음 예제에서는 4자로 된 단어의 배열을 정의하고 개별 문자를 문자열 배열에 저장하여 배열을 스크램블링합니다. 그런 다음 메서드를 Concat(String, String, String, String) 호출하여 스크램블된 단어를 다시 어셈블합니다.
using System;
using System.Collections;
public class Example
{
public static void Main()
{
const int WORD_SIZE = 4;
// Define some 4-letter words to be scrambled.
string[] words = { "home", "food", "game", "rest" };
// Define two arrays equal to the number of letters in each word.
double[] keys = new double[WORD_SIZE];
string[] letters = new string[WORD_SIZE];
// Initialize the random number generator.
Random rnd = new Random();
// Scramble each word.
foreach (string word in words)
{
for (int ctr = 0; ctr < word.Length; ctr++)
{
// Populate the array of keys with random numbers.
keys[ctr] = rnd.NextDouble();
// Assign a letter to the array of letters.
letters[ctr] = word[ctr].ToString();
}
// Sort the array.
Array.Sort(keys, letters, 0, WORD_SIZE, Comparer.Default);
// Display the scrambled word.
string scrambledWord = String.Concat(letters[0], letters[1],
letters[2], letters[3]);
Console.WriteLine("{0} --> {1}", word, scrambledWord);
}
}
}
// The example displays output like the following:
// home --> mheo
// food --> oodf
// game --> aemg
// rest --> trse
open System
open System.Collections
let WORD_SIZE = 4
// Define some 4-letter words to be scrambled.
let words = [| "home"; "food"; "game"; "rest" |]
// Define two arrays equal to the number of letters in each word.
let keys = Array.zeroCreate<float> WORD_SIZE
let letters = Array.zeroCreate<string> WORD_SIZE
// Initialize the random number generator.
let rnd = Random()
// Scramble each word.
for word in words do
for i = 0 to word.Length - 1 do
// Populate the array of keys with random numbers.
keys[i] <- rnd.NextDouble()
// Assign a letter to the array of letters.
letters[i] <- string word[i]
// Sort the array.
Array.Sort(keys, letters, 0, WORD_SIZE, Comparer.Default)
// Display the scrambled word.
let scrambledWord = String.Concat(letters[0], letters[1], letters[2], letters[3])
printfn $"{word} --> {scrambledWord}"
// The example displays output like the following:
// home --> mheo
// food --> oodf
// game --> aemg
// rest --> trse
Imports System.Collections
Module Example
Public Sub Main()
Const WORD_SIZE As Integer = 4
' Define some 4-letter words to be scrambled.
Dim words() As String = { "home", "food", "game", "rest" }
' Define two arrays equal to the number of letters in each word.
Dim keys(WORD_SIZE) As Double
Dim letters(WORD_SIZE) As String
' Initialize the random number generator.
Dim rnd As New Random()
' Scramble each word.
For Each word As String In words
For ctr As Integer = 0 To word.Length - 1
' Populate the array of keys with random numbers.
keys(ctr) = rnd.NextDouble()
' Assign a letter to the array of letters.
letters(ctr) = word.Chars(ctr)
Next
' Sort the array.
Array.Sort(keys, letters, 0, WORD_SIZE, Comparer.Default)
' Display the scrambled word.
Dim scrambledWord As String = String.Concat(letters(0), letters(1), _
letters(2), letters(3))
Console.WriteLine("{0} --> {1}", word, scrambledWord)
Next
End Sub
End Module
' The example displays output like the following:
' home --> mheo
' food --> oodf
' game --> aemg
' rest --> trse
설명
메서드는 , , str1
str2
및 를 연결str0
하며 str3
구분 기호를 추가하지 않습니다.
추가 정보
적용 대상
Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>)
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
지정된 네 개의 읽기 전용 문자 범위의 문자열 표현을 연결합니다.
public:
static System::String ^ Concat(ReadOnlySpan<char> str0, ReadOnlySpan<char> str1, ReadOnlySpan<char> str2, ReadOnlySpan<char> str3);
public static string Concat (ReadOnlySpan<char> str0, ReadOnlySpan<char> str1, ReadOnlySpan<char> str2, ReadOnlySpan<char> str3);
static member Concat : ReadOnlySpan<char> * ReadOnlySpan<char> * ReadOnlySpan<char> * ReadOnlySpan<char> -> string
Public Shared Function Concat (str0 As ReadOnlySpan(Of Char), str1 As ReadOnlySpan(Of Char), str2 As ReadOnlySpan(Of Char), str3 As ReadOnlySpan(Of Char)) As String
매개 변수
- str0
- ReadOnlySpan<Char>
연결할 첫 번째 읽기 전용 문자 범위입니다.
- str1
- ReadOnlySpan<Char>
연결할 두 번째 읽기 전용 문자 범위입니다.
- str2
- ReadOnlySpan<Char>
연결할 세 번째 읽기 전용 문자 범위입니다.
- str3
- ReadOnlySpan<Char>
연결할 네 번째 읽기 전용 문자 범위입니다.
반환
str0
, str1
, str2
및 str3
값의 연결된 문자열 표현입니다.
적용 대상
Concat(Object, Object, Object, Object)
중요
이 API는 CLS 규격이 아닙니다.
지정된 네 개체의 문자열 표현과 선택적 변수 길이 매개 변수 목록에 지정된 개체를 연결합니다.
public:
static System::String ^ Concat(System::Object ^ arg0, System::Object ^ arg1, System::Object ^ arg2, System::Object ^ arg3);
[System.CLSCompliant(false)]
public static string Concat (object arg0, object arg1, object arg2, object arg3);
[<System.CLSCompliant(false)>]
static member Concat : obj * obj * obj * obj -> string
Public Shared Function Concat (arg0 As Object, arg1 As Object, arg2 As Object, arg3 As Object) As String
매개 변수
- arg0
- Object
연결할 첫 번째 개체입니다.
- arg1
- Object
연결할 두 번째 개체입니다.
- arg2
- Object
연결할 세 번째 개체입니다.
- arg3
- Object
연결할 네 번째 개체입니다.
반환
매개 변수 목록에서 각 값의 연결된 문자열 표현입니다.
- 특성
예제
다음 예제에서는 메서드를 사용하여 Concat(Object, Object, Object, Object) 변수 매개 변수 목록을 연결합니다. 이 경우 메서드는 9개의 매개 변수를 사용하여 호출됩니다.
using System;
using System.Collections;
public class Example
{
public static void Main()
{
const int WORD_SIZE = 4;
// Define some 4-letter words to be scrambled.
string[] words = { "home", "food", "game", "rest" };
// Define two arrays equal to the number of letters in each word.
double[] keys = new double[WORD_SIZE];
string[] letters = new string[WORD_SIZE];
// Initialize the random number generator.
Random rnd = new Random();
// Scramble each word.
foreach (string word in words)
{
for (int ctr = 0; ctr < word.Length; ctr++)
{
// Populate the array of keys with random numbers.
keys[ctr] = rnd.NextDouble();
// Assign a letter to the array of letters.
letters[ctr] = word[ctr].ToString();
}
// Sort the array.
Array.Sort(keys, letters, 0, WORD_SIZE, Comparer.Default);
// Display the scrambled word.
string scrambledWord = String.Concat(letters[0], letters[1],
letters[2], letters[3]);
Console.WriteLine("{0} --> {1}", word, scrambledWord);
}
}
}
// The example displays output like the following:
// home --> mheo
// food --> oodf
// game --> aemg
// rest --> trse
open System
open System.Collections
let WORD_SIZE = 4
// Define some 4-letter words to be scrambled.
let words = [| "home"; "food"; "game"; "rest" |]
// Define two arrays equal to the number of letters in each word.
let keys = Array.zeroCreate<float> WORD_SIZE
let letters = Array.zeroCreate<string> WORD_SIZE
// Initialize the random number generator.
let rnd = Random()
// Scramble each word.
for word in words do
for i = 0 to word.Length - 1 do
// Populate the array of keys with random numbers.
keys[i] <- rnd.NextDouble()
// Assign a letter to the array of letters.
letters[i] <- string word[i]
// Sort the array.
Array.Sort(keys, letters, 0, WORD_SIZE, Comparer.Default)
// Display the scrambled word.
let scrambledWord = String.Concat(letters[0], letters[1], letters[2], letters[3])
printfn $"{word} --> {scrambledWord}"
// The example displays output like the following:
// home --> mheo
// food --> oodf
// game --> aemg
// rest --> trse
Imports System.Collections
Module Example
Public Sub Main()
Const WORD_SIZE As Integer = 4
' Define some 4-letter words to be scrambled.
Dim words() As String = { "home", "food", "game", "rest" }
' Define two arrays equal to the number of letters in each word.
Dim keys(WORD_SIZE) As Double
Dim letters(WORD_SIZE) As String
' Initialize the random number generator.
Dim rnd As New Random()
' Scramble each word.
For Each word As String In words
For ctr As Integer = 0 To word.Length - 1
' Populate the array of keys with random numbers.
keys(ctr) = rnd.NextDouble()
' Assign a letter to the array of letters.
letters(ctr) = word.Chars(ctr)
Next
' Sort the array.
Array.Sort(keys, letters, 0, WORD_SIZE, Comparer.Default)
' Display the scrambled word.
Dim scrambledWord As String = String.Concat(letters(0), letters(1), _
letters(2), letters(3))
Console.WriteLine("{0} --> {1}", word, scrambledWord)
Next
End Sub
End Module
' The example displays output like the following:
' home --> mheo
' food --> oodf
' game --> aemg
' rest --> trse
설명
참고
이 API는 CLS 규격이 아닙니다. CLS 규격 대체 항목은 String.Concat(Object[])입니다. C# 및 Visual Basic 컴파일러에서는 이 메서드에 대한 호출을 에 대한 호출String.Concat(Object[])로 자동으로 resolve.
메서드는 매개 변수가 없는 ToString
메서드를 호출하여 매개 변수 목록의 각 개체를 연결합니다. 구분 기호는 추가하지 않습니다.
String.Empty 는 null 인수 대신 사용됩니다.
참고
메서드의 Concat 마지막 매개 변수는 연결할 하나 이상의 추가 개체의 선택적 쉼표로 구분된 목록입니다.
호출자 참고
이 메서드는 가변 개수의 vararg
매개 변수를 지원하는 키워드(keyword) 표시됩니다. 메서드는 Visual C++에서 호출할 수 있지만 C# 또는 Visual Basic 코드에서는 호출할 수 없습니다. C# 및 Visual Basic 컴파일러에서 호출을 Concat(Object, Object, Object, Object) 에 대한 호출Concat(Object[])로 resolve.
적용 대상
Concat(String, String, String)
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
String의 지정된 세 인스턴스를 연결합니다.
public:
static System::String ^ Concat(System::String ^ str0, System::String ^ str1, System::String ^ str2);
public static string Concat (string str0, string str1, string str2);
public static string Concat (string? str0, string? str1, string? str2);
static member Concat : string * string * string -> string
Public Shared Function Concat (str0 As String, str1 As String, str2 As String) As String
매개 변수
- str0
- String
연결할 첫 번째 문자열입니다.
- str1
- String
연결할 두 번째 문자열입니다.
- str2
- String
연결할 세 번째 문자열입니다.
반환
연결된 str0
, str1
및 str2
를 반환합니다.
예제
다음 예제에서는 메서드를 Concat 사용하여 세 개의 문자열을 연결하고 결과를 표시합니다.
using namespace System;
void main()
{
String^ s1 = "We went to a bookstore, ";
String^ s2 = "a movie, ";
String^ s3 = "and a restaurant.";
String^ s = String::Concat(s1, s2, s3);
Console::WriteLine(s);
}
// The example displays the following output:
// We went to a bookstore, a movie, and a restaurant.
using System;
public class Example
{
public static void Main()
{
String s1 = "We went to a bookstore, ";
String s2 = "a movie, ";
String s3 = "and a restaurant.";
var s = String.Concat(s1, s2, s3);
Console.WriteLine(s);
}
}
// The example displays the following output:
// We went to a bookstore, a movie, and a restaurant.
open System
let s1 = "We went to a bookstore, "
let s2 = "a movie, "
let s3 = "and a restaurant."
String.Concat(s1, s2, s3)
|> printfn "%s"
// The example displays the following output:
// We went to a bookstore, a movie, and a restaurant.
Public Module Example
Public Sub Main()
Dim s1 As String = "We went to a bookstore, "
Dim s2 As String = "a movie, "
Dim s3 As String = "and a restaurant."
Dim s = String.Concat(s1, s2, s3)
Console.WriteLine(s)
End Sub
End Module
' The example displays the following output:
' We went to a bookstore, a movie, and a restaurant.
설명
메서드는 , str1
및 를 연결str0
하며 str2
구분 기호를 추가하지 않습니다.
추가 정보
적용 대상
Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>)
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
지정된 세 개의 읽기 전용 문자 범위의 문자열 표현을 연결합니다.
public:
static System::String ^ Concat(ReadOnlySpan<char> str0, ReadOnlySpan<char> str1, ReadOnlySpan<char> str2);
public static string Concat (ReadOnlySpan<char> str0, ReadOnlySpan<char> str1, ReadOnlySpan<char> str2);
static member Concat : ReadOnlySpan<char> * ReadOnlySpan<char> * ReadOnlySpan<char> -> string
Public Shared Function Concat (str0 As ReadOnlySpan(Of Char), str1 As ReadOnlySpan(Of Char), str2 As ReadOnlySpan(Of Char)) As String
매개 변수
- str0
- ReadOnlySpan<Char>
연결할 첫 번째 읽기 전용 문자 범위입니다.
- str1
- ReadOnlySpan<Char>
연결할 두 번째 읽기 전용 문자 범위입니다.
- str2
- ReadOnlySpan<Char>
연결할 세 번째 읽기 전용 문자 범위입니다.
반환
str0
, str1
및 str2
값의 연결된 문자열 표현입니다.
적용 대상
Concat(Object, Object, Object)
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
지정된 세 개체의 문자열 표현을 연결합니다.
public:
static System::String ^ Concat(System::Object ^ arg0, System::Object ^ arg1, System::Object ^ arg2);
public static string Concat (object arg0, object arg1, object arg2);
public static string Concat (object? arg0, object? arg1, object? arg2);
static member Concat : obj * obj * obj -> string
Public Shared Function Concat (arg0 As Object, arg1 As Object, arg2 As Object) As String
매개 변수
- arg0
- Object
연결할 첫 번째 개체입니다.
- arg1
- Object
연결할 두 번째 개체입니다.
- arg2
- Object
연결할 세 번째 개체입니다.
반환
arg0
, arg1
및 arg2
값의 연결된 문자열 표현입니다.
예제
다음 예제는 Concat 메서드.
using namespace System;
int main()
{
int i = -123;
Object^ o = i;
array<Object^>^objs = { -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
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
open System
let i = -123
let o: obj = i
let objs: obj[] = [| -123; -456; -789 |]
printfn "Concatenate 1, 2, and 3 objects:"
printfn $"1) {String.Concat o}"
printfn $"2) {String.Concat(o, o)}"
printfn $"3) {String.Concat(o, o, o)}"
printfn "\nConcatenate 4 objects and a variable length parameter list:"
printfn $"4) {String.Concat(o, o, o, o)}"
printfn $"5) {String.Concat(o, o, o, o, o)}"
printfn "\nConcatenate a 3-element object array:"
printfn $"6) {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
Class stringConcat5
Public Shared Sub Main()
Dim i As Integer = - 123
Dim o As [Object] = i
Dim objs() As [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(vbCrLf & "Concatenate 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(vbCrLf & "Concatenate a 3-element object array:")
Console.WriteLine("6) {0}", [String].Concat(objs))
End Sub
End Class
'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
설명
메서드는 각 개체의 매개 변수가 없는 ToString
메서드를 호출하여 , arg1
및 arg2
를 연결arg0
합니다. 구분 기호는 추가하지 않습니다.
String.Empty 는 null 인수 대신 사용됩니다.
추가 정보
적용 대상
Concat(String, String)
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
String의 지정된 두 인스턴스를 연결합니다.
public:
static System::String ^ Concat(System::String ^ str0, System::String ^ str1);
public static string Concat (string str0, string str1);
public static string Concat (string? str0, string? str1);
static member Concat : string * string -> string
Public Shared Function Concat (str0 As String, str1 As String) As String
매개 변수
- str0
- String
연결할 첫 번째 문자열입니다.
- str1
- String
연결할 두 번째 문자열입니다.
반환
연결된 str0
및 str1
을 반환합니다.
예제
다음 예제에서는 사람의 첫 번째, 중간 및 성을 연결합니다.
using namespace System;
int main()
{
// we want to simply quickly add this person's name together
String^ fName = "Simon";
String^ mName = "Jake";
String^ lName = "Harrows";
// because we want a name to appear with a space in between each name,
// put a space on the front of the middle, and last name, allowing for
// the fact that a space may already be there
mName = String::Concat( " ", mName->Trim() );
lName = String::Concat( " ", lName->Trim() );
// this line simply concatenates the two strings
Console::WriteLine( "Welcome to this page, '{0}'!", String::Concat( String::Concat( fName, mName ), lName ) );
}
// The example displays the following output:
// Welcome to this page, 'Simon Jake Harrows'!
using System;
public class ConcatTest {
public static void Main() {
// we want to simply quickly add this person's name together
string fName = "Simon";
string mName = "Jake";
string lName = "Harrows";
// because we want a name to appear with a space in between each name,
// put a space on the front of the middle, and last name, allowing for
// the fact that a space may already be there
mName = " " + mName.Trim();
lName = " " + lName.Trim();
// this line simply concatenates the two strings
Console.WriteLine("Welcome to this page, '{0}'!", string.Concat( string.Concat(fName, mName), lName ) );
}
}
// The example displays the following output:
// Welcome to this page, 'Simon Jake Harrows'!
open System
[<EntryPoint>]
let main _ =
// we want to simply quickly add this person's name together
let fName = "Simon"
let mName = "Jake"
let lName = "Harrows"
// because we want a name to appear with a space in between each name,
// put a space on the front of the middle, and last name, allowing for
// the fact that a space may already be there
let mName = " " + mName.Trim()
let lName = " " + lName.Trim()
// this line simply concatenates the two strings
printfn $"Welcome to this page, '{String.Concat(String.Concat(fName, mName), lName)}'!"
0
// The example displays the following output:
// Welcome to this page, 'Simon Jake Harrows'!
Public Class ConcatTest
Public Shared Sub Main()
Dim fName As String = "Simon"
Dim mName As String = "Jake"
Dim lName As String = "Harrows"
' We want to simply quickly add this person's name together.
' Because we want a name to appear with a space in between each name,
' we put a space on the front of the middle, and last name, allowing for
' the fact that a space may already be there.
mName = " " + mName.Trim()
lName = " " + lName.Trim()
' This line simply concatenates the two strings.
Console.WriteLine("Welcome to this page, '{0}'!", _
String.Concat(String.Concat(fName, mName), lName))
End Sub
End Class
' The example displays the following output:
' Welcome to this page, 'Simon Jake Harrows'!
설명
메서드는 및 를 연결 str0
합니다 str1
. 구분 기호는 추가하지 않습니다.
Empty 문자열은 null 인수 대신 사용됩니다.
추가 정보
적용 대상
Concat(Object)
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
지정된 개체의 문자열 표현을 만듭니다.
public:
static System::String ^ Concat(System::Object ^ arg0);
public static string Concat (object arg0);
public static string Concat (object? arg0);
static member Concat : obj -> string
Public Shared Function Concat (arg0 As Object) As String
매개 변수
- arg0
- Object
나타낼 개체나 null
입니다.
반환
arg0
이 Empty인 경우 arg0
또는 null
값의 문자열 표현입니다.
예제
다음 예제는 Concat 메서드.
using namespace System;
int main()
{
int i = -123;
Object^ o = i;
array<Object^>^objs = { -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
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
open System
let i = -123
let o: obj = i
let objs: obj[] = [| -123; -456; -789 |]
printfn "Concatenate 1, 2, and 3 objects:"
printfn $"1) {String.Concat o}"
printfn $"2) {String.Concat(o, o)}"
printfn $"3) {String.Concat(o, o, o)}"
printfn "\nConcatenate 4 objects and a variable length parameter list:"
printfn $"4) {String.Concat(o, o, o, o)}"
printfn $"5) {String.Concat(o, o, o, o, o)}"
printfn "\nConcatenate a 3-element object array:"
printfn $"6) {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
Class stringConcat5
Public Shared Sub Main()
Dim i As Integer = - 123
Dim o As [Object] = i
Dim objs() As [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(vbCrLf & "Concatenate 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(vbCrLf & "Concatenate a 3-element object array:")
Console.WriteLine("6) {0}", [String].Concat(objs))
End Sub
End Class
'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(Object) 매개 변수가 없는 ToString
메서드를 호출하여 문자열로 나타냅니다arg0
.
추가 정보
적용 대상
Concat(Object, Object)
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
지정된 두 개체의 문자열 표현을 연결합니다.
public:
static System::String ^ Concat(System::Object ^ arg0, System::Object ^ arg1);
public static string Concat (object arg0, object arg1);
public static string Concat (object? arg0, object? arg1);
static member Concat : obj * obj -> string
Public Shared Function Concat (arg0 As Object, arg1 As Object) As String
매개 변수
- arg0
- Object
연결할 첫 번째 개체입니다.
- arg1
- Object
연결할 두 번째 개체입니다.
반환
arg0
및 arg1
값의 연결된 문자열 표현입니다.
예제
다음 예제는 Concat 메서드.
using namespace System;
int main()
{
int i = -123;
Object^ o = i;
array<Object^>^objs = { -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
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
open System
let i = -123
let o: obj = i
let objs: obj[] = [| -123; -456; -789 |]
printfn "Concatenate 1, 2, and 3 objects:"
printfn $"1) {String.Concat o}"
printfn $"2) {String.Concat(o, o)}"
printfn $"3) {String.Concat(o, o, o)}"
printfn "\nConcatenate 4 objects and a variable length parameter list:"
printfn $"4) {String.Concat(o, o, o, o)}"
printfn $"5) {String.Concat(o, o, o, o, o)}"
printfn "\nConcatenate a 3-element object array:"
printfn $"6) {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
Class stringConcat5
Public Shared Sub Main()
Dim i As Integer = - 123
Dim o As [Object] = i
Dim objs() As [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(vbCrLf & "Concatenate 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(vbCrLf & "Concatenate a 3-element object array:")
Console.WriteLine("6) {0}", [String].Concat(objs))
End Sub
End Class
'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
설명
메서드는 및 arg1
의 arg0
매개 변수 없는 ToString
메서드를 호출하여 및 를 연결 arg0
하며 arg1
구분 기호를 추가하지 않습니다.
String.Empty 는 null 인수 대신 사용됩니다.
인수 중 하나가 배열 참조인 경우 메서드는 해당 멤버 대신 해당 배열을 나타내는 문자열을 연결합니다(예: "System.String[]").
추가 정보
적용 대상
Concat(String[])
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
중요
이 API는 CLS 규격이 아닙니다.
지정된 String 배열의 요소를 연결합니다.
public:
static System::String ^ Concat(... cli::array <System::String ^> ^ values);
public static string Concat (params string[] values);
public static string Concat (params string?[] values);
[System.CLSCompliant(false)]
public static string Concat (params string[] values);
static member Concat : string[] -> string
[<System.CLSCompliant(false)>]
static member Concat : string[] -> string
Public Shared Function Concat (ParamArray values As String()) As String
매개 변수
- values
- String[]
문자열 인스턴스의 배열입니다.
반환
values
의 연결된 요소를 반환합니다.
- 특성
예외
values
은 null
입니다.
메모리가 부족합니다.
예제
다음 예제에서는 배열과 함께 메서드를 Concat 사용하는 방법을 보여 줍니다 String .
using namespace System;
int main()
{
// Make an array of strings. Note that we have included spaces.
array<String^>^s = { "hello ", "and ", "welcome ", "to ",
"this ", "demo! "};
// Put all the strings together.
Console::WriteLine( String::Concat(s) );
// Sort the strings, and put them together.
Array::Sort( s );
Console::WriteLine( String::Concat(s));
}
// The example displays the following output:
// hello and welcome to this demo!
// and demo! hello this to welcome
using System;
public class Example
{
public static void Main()
{
// Make an array of strings. Note that we have included spaces.
string [] s = { "hello ", "and ", "welcome ", "to ",
"this ", "demo! " };
// Put all the strings together.
Console.WriteLine(string.Concat(s));
// Sort the strings, and put them together.
Array.Sort(s);
Console.WriteLine(string.Concat(s));
}
}
// The example displays the following output:
// hello and welcome to this demo!
// and demo! hello this to welcome
open System
// Make an array of strings. Note that we have included spaces.
let s =
[| "hello "; "and "; "welcome "; "to "
"this "; "demo! " |]
// Put all the strings together.
printfn $"{String.Concat s}"
// Sort the strings, and put them together.
Array.Sort s
printfn $"{String.Concat s}"
// The example displays the following output:
// hello and welcome to this demo!
// and demo! hello this to welcome
Public Class Example
Public Shared Sub Main()
' Make an array of strings. Note that we have included spaces.
Dim s As String() = { "hello ", "and ", "welcome ", "to ",
"this ", "demo! "}
' Put all the strings together.
Console.WriteLine(String.Concat(s))
' Sort the strings, and put them together.
Array.Sort(s)
Console.WriteLine(String.Concat(s))
End Sub
End Class
' The example displays the following output:
' hello and welcome to this demo!
' and demo! hello this to welcome
설명
메서드는 의 각 개체를 values
연결합니다. 구분 기호는 추가하지 않습니다.
Empty 문자열은 배열의 null 개체 대신 사용됩니다.
추가 정보
적용 대상
Concat(ReadOnlySpan<String>)
public:
static System::String ^ Concat(ReadOnlySpan<System::String ^> values);
public static string Concat (ReadOnlySpan<string?> values);
static member Concat : ReadOnlySpan<string> -> string
Public Shared Function Concat (values As ReadOnlySpan(Of String)) As String
매개 변수
- values
- ReadOnlySpan<String>
반환
적용 대상
Concat(ReadOnlySpan<Object>)
public:
static System::String ^ Concat(ReadOnlySpan<System::Object ^> args);
public static string Concat (ReadOnlySpan<object?> args);
static member Concat : ReadOnlySpan<obj> -> string
Public Shared Function Concat (args As ReadOnlySpan(Of Object)) As String
매개 변수
- args
- ReadOnlySpan<Object>
반환
적용 대상
Concat(Object[])
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
지정된 Object 배열에 있는 요소의 문자열 표현을 연결합니다.
public:
static System::String ^ Concat(... cli::array <System::Object ^> ^ args);
public static string Concat (params object[] args);
public static string Concat (params object?[] args);
static member Concat : obj[] -> string
Public Shared Function Concat (ParamArray args As Object()) As String
매개 변수
- args
- Object[]
연결할 요소가 포함된 개체 배열입니다.
반환
args
에 있는 요소 값의 연결된 문자열 표현입니다.
예외
args
은 null
입니다.
메모리가 부족합니다.
예제
다음 예제에서는 배열과 함께 메서드를 Concat 사용하는 방법을 보여 줍니다 Object .
using System;
public class ConcatTest {
public static void Main() {
// Create a group of objects.
Test1 t1 = new Test1();
Test2 t2 = new Test2();
int i = 16;
string s = "Demonstration";
// Place the objects in an array.
object [] o = { t1, i, t2, s };
// Concatenate the objects together as a string. To do this,
// the ToString method of each of the objects is called.
Console.WriteLine(string.Concat(o));
}
}
// Create two empty test classes.
class Test1 {
}
class Test2 {
}
// The example displays the following output:
// Test116Test2Demonstration
open System
// Create two empty test classes.
type Test1() = class end
type Test2() = class end
// Create a group of objects.
let t1 = new Test1()
let t2 = new Test2()
let i = 16
let s = "Demonstration"
// Place the objects in an array.
let o: obj[] = [| t1; i; t2; s |]
// Concatenate the objects together as a string. To do this,
// the ToString method of each of the objects is called.
printfn $"{String.Concat o}"
// The example displays the following output:
// Test116Test2Demonstration
Public Class ConcatTest
Public Shared Sub Main()
Dim t1 As New Test1()
Dim t2 As New Test2()
Dim i As Integer = 16
Dim s As String = "Demonstration"
Dim o As Object() = {t1, i, t2, s}
' create a group of objects
' place the objects in an array
' concatenate the objects together as a string. To do this,
' the ToString method in the objects is called
Console.WriteLine(String.Concat(o))
End Sub
End Class
' imagine these test classes are full-fledged objects...
Class Test1
End Class
Class Test2
End Class
설명
메서드는 해당 개체 args
의 매개 변수 없는 ToString
메서드를 호출하여 의 각 개체를 연결합니다. 구분 기호는 추가하지 않습니다.
String.Empty 는 배열의 null 개체 대신 사용됩니다.
호출자 참고
이 메서드는 C++ 코드에서 호출되지 않습니다. C++ 컴파일러는 4개 이상의 개체 매개 변수가 있는 에 대한 호출 Concat 을 에 대한 호출 Concat(Object, Object, Object, Object)로 확인합니다.
추가 정보
적용 대상
Concat(IEnumerable<String>)
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
IEnumerable<T> 형식의 생성된 String 컬렉션의 멤버를 연결합니다.
public:
static System::String ^ Concat(System::Collections::Generic::IEnumerable<System::String ^> ^ values);
public static string Concat (System.Collections.Generic.IEnumerable<string> values);
public static string Concat (System.Collections.Generic.IEnumerable<string?> values);
[System.Runtime.InteropServices.ComVisible(false)]
public static string Concat (System.Collections.Generic.IEnumerable<string> values);
static member Concat : seq<string> -> string
[<System.Runtime.InteropServices.ComVisible(false)>]
static member Concat : seq<string> -> string
Public Shared Function Concat (values As IEnumerable(Of String)) As String
매개 변수
- values
- IEnumerable<String>
IEnumerable<T>을 구현하고 제네릭 형식 인수가 String인 컬렉션 개체입니다.
반환
values
의 연결된 문자열이거나, values
가 빈 IEnumerable(Of String)
이면 Empty입니다.
- 특성
예외
values
은 null
입니다.
예제
다음 예제에서는 Eratosthenes의 Sieve 알고리즘을 사용하여 100보다 작거나 같은 소수를 계산합니다. 결과를 형식String의 개체에 List<T> 할당한 다음 메서드에 Concat(IEnumerable<String>) 전달합니다.
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
open System
let getPrimes maxPrime =
let values = Array.CreateInstance(typeof<int>, [| maxPrime - 1|], [| 2 |])
// Use Sieve of Erathsthenes to determine prime numbers.
for i = values.GetLowerBound 0 to values.GetUpperBound 0 |> float |> sqrt |> ceil |> int do
if values.GetValue i :?> int <> 1 then
for multiplier = i to maxPrime / 2 do
if i * multiplier <= maxPrime then
values.SetValue(1, i * multiplier)
seq {
for i = values.GetLowerBound 0 to values.GetUpperBound 0 do
if values.GetValue i :?> int = 0 then
string i + " "
}
let maxPrime = 100
let primeList = getPrimes maxPrime
printfn $"Primes less than {maxPrime}:"
printfn $" {String.Concat primeList}"
// 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
Imports System.Collections.Generic
Module Example
Public Sub Main()
Dim maxPrime As Integer = 100
Dim primeList As IEnumerable(Of String) = GetPrimes(maxPrime)
Console.WriteLine("Primes less than {0}:", maxPrime)
Console.WriteLine(" {0}", String.Concat(primeList))
End Sub
Private Function GetPrimes(maxPrime As Integer) As IEnumerable(Of String)
Dim values As Array = Array.CreateInstance(GetType(Integer), _
New Integer() { maxPrime - 1}, New Integer(){ 2 })
' Use Sieve of Erathsthenes to determine prime numbers.
For ctr As Integer = values.GetLowerBound(0) To _
CInt(Math.Ceiling(Math.Sqrt(values.GetUpperBound(0))))
If CInt(values.GetValue(ctr)) = 1 Then Continue For
For multiplier As Integer = ctr To maxPrime \ 2
If ctr * multiplier <= maxPrime Then values.SetValue(1, ctr * multiplier)
Next
Next
Dim primes As New List(Of String)
For ctr As Integer = values.GetLowerBound(0) To values.GetUpperBound(0)
If CInt(values.GetValue(ctr)) = 0 Then primes.Add(ctr.ToString() + " ")
Next
Return primes
End Function
End Module
' 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
설명
메서드는 의 각 개체를 values
연결합니다. 구분 기호는 추가하지 않습니다. 의 각 멤버 간에 구분 기호를 values
지정하려면 메서드를 호출합니다 Join(String, IEnumerable<String>) .
Empty 문자열은 의 null 요소 values
대신 사용됩니다.
If values
이면 IEnumerable(Of String)
이면 메서드에서 String.Empty입니다. 가 이null
면 values
메서드가 예외를 ArgumentNullException throw합니다.
Concat(IEnumerable<String>) 는 요소를 문자열 배열로 먼저 변환하지 않고 컬렉션의 IEnumerable(Of String)
각 요소를 연결할 수 있는 편리한 메서드입니다. LINQ(Language-Integrated Query) 쿼리 식에 특히 유용합니다. 다음 예제에서는 알파벳의 대문자나 소문자가 포함된 개체를 특정 문자와 같거나 큰 문자를 선택하는 람다 식에 전달 List(Of String)
합니다(예에서는 "M"). IEnumerable(Of String)
메서드에서 반환 Enumerable.Where 되는 컬렉션은 결과를 단일 문자열로 표시하기 위해 메서드에 전달 Concat(IEnumerable<String>) 됩니다.
using System;
using System.Collections.Generic;
using System.Linq;
public class Example
{
public static void Main()
{
string output = String.Concat( GetAlphabet(true).Where( letter =>
letter.CompareTo("M") >= 0));
Console.WriteLine(output);
}
private static List<string> GetAlphabet(bool upper)
{
List<string> alphabet = new List<string>();
int charValue = upper ? 65 : 97;
for (int ctr = 0; ctr <= 25; ctr++)
alphabet.Add(((char)(charValue + ctr)).ToString());
return alphabet;
}
}
// The example displays the following output:
// MNOPQRSTUVWXYZ
// This example uses the F# Seq.filter function instead of Linq.
open System
let getAlphabet upper =
let charValue = if upper then 65 else 97
seq {
for i = 0 to 25 do
charValue + i |> char |> string
}
getAlphabet true
|> Seq.filter (fun letter -> letter.CompareTo "M" >= 0)
|> String.Concat
|> printfn "%s"
// The example displays the following output:
// MNOPQRSTUVWXYZ
Imports System.Collections.Generic
Imports System.Linq
Module modMain
Public Sub Main()
Dim output As String = String.Concat(GetAlphabet(true).Where(Function(letter) _
letter >= "M"))
Console.WriteLine(output)
End Sub
Private Function GetAlphabet(upper As Boolean) As List(Of String)
Dim alphabet As New List(Of String)
Dim charValue As Integer = CInt(IIf(upper, 65, 97))
For ctr As Integer = 0 To 25
alphabet.Add(ChrW(charValue + ctr).ToString())
Next
Return alphabet
End Function
End Module
' The example displays the following output:
' MNOPQRSTUVWXYZ
적용 대상
Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>)
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
지정된 두 개의 읽기 전용 문자 범위의 문자열 표현을 연결합니다.
public:
static System::String ^ Concat(ReadOnlySpan<char> str0, ReadOnlySpan<char> str1);
public static string Concat (ReadOnlySpan<char> str0, ReadOnlySpan<char> str1);
static member Concat : ReadOnlySpan<char> * ReadOnlySpan<char> -> string
Public Shared Function Concat (str0 As ReadOnlySpan(Of Char), str1 As ReadOnlySpan(Of Char)) As String
매개 변수
- str0
- ReadOnlySpan<Char>
연결할 첫 번째 읽기 전용 문자 범위입니다.
- str1
- ReadOnlySpan<Char>
연결할 두 번째 읽기 전용 문자 범위입니다.
반환
str0
및 str1
값의 연결된 문자열 표현입니다.
적용 대상
Concat<T>(IEnumerable<T>)
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
IEnumerable<T> 구현의 멤버를 연결합니다.
public:
generic <typename T>
static System::String ^ Concat(System::Collections::Generic::IEnumerable<T> ^ values);
public static string Concat<T> (System.Collections.Generic.IEnumerable<T> values);
[System.Runtime.InteropServices.ComVisible(false)]
public static string Concat<T> (System.Collections.Generic.IEnumerable<T> values);
static member Concat : seq<'T> -> string
[<System.Runtime.InteropServices.ComVisible(false)>]
static member Concat : seq<'T> -> string
Public Shared Function Concat(Of T) (values As IEnumerable(Of T)) As String
형식 매개 변수
- T
values
멤버의 형식입니다.
매개 변수
- values
- IEnumerable<T>
IEnumerable<T> 인터페이스를 구현하는 컬렉션 개체입니다.
반환
values
의 연결된 멤버입니다.
- 특성
예외
values
은 null
입니다.
예제
다음 예제에서는 동물의 이름과 해당 항목이 속한 순서를 포함하는 매우 간단한 Animal
클래스를 정의합니다. 그런 다음, 여러 Animal
개체를 List<T> 포함할 개체를 정의합니다. Enumerable.Where 확장 메서드는 속성이 "Rodent"와 같은 개체를 Order
추출 Animal
하기 위해 호출됩니다. 결과는 메서드에 Concat<T>(IEnumerable<T>) 전달되고 콘솔에 표시됩니다.
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
// This example uses the F# Seq.filter function instead of Linq.
open System
type Animal =
{ Kind: string
Order: string }
override this.ToString() =
this.Kind
let animals = ResizeArray()
animals.Add { Kind = "Squirrel"; Order = "Rodent" }
animals.Add { Kind = "Gray Wolf"; Order = "Carnivora" }
animals.Add { Kind = "Capybara"; Order = "Rodent" }
Seq.filter (fun animal -> animal.Order = "Rodent")
|> String.Concat
|> printfn "%s"
// The example displays the following output:
// SquirrelCapybara
Imports System.Collections.Generic
Public Class Animal
Public Kind As String
Public Order As String
Public Sub New(kind As String, order As String)
Me.Kind = kind
Me.Order = order
End Sub
Public Overrides Function ToString() As String
Return Me.Kind
End Function
End Class
Module Example
Public Sub Main()
Dim animals As New List(Of Animal)
animals.Add(New Animal("Squirrel", "Rodent"))
animals.Add(New Animal("Gray Wolf", "Carnivora"))
animals.Add(New Animal("Capybara", "Rodent"))
Dim output As String = String.Concat(animals.Where(Function(animal) _
animal.Order = "Rodent"))
Console.WriteLine(output)
End Sub
End Module
' The example displays the following output:
' SquirrelCapybara
설명
메서드는 의 각 개체를 values
연결합니다. 구분 기호는 추가하지 않습니다.
Empty 문자열은 null 인수 대신 사용됩니다.
Concat<T>(IEnumerable<T>) 는 요소를 문자열로 먼저 변환하지 않고 컬렉션의 IEnumerable<T> 각 요소를 연결할 수 있는 편리한 메서드입니다. 예제와 같이 LINQ(Language-Integrated Query) 쿼리 식에 특히 유용합니다. 컬렉션에 있는 IEnumerable<T> 각 개체의 문자열 표현은 해당 개체의 ToString
메서드를 호출하여 파생됩니다.
적용 대상
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기