String.Concat メソッド (String, String)
指定した 2 つの String インスタンスを連結します。
Overloads Public Shared Function Concat( _
ByVal str0 As String, _ ByVal str1 As String _) As String
[C#]
public static string Concat(stringstr0,stringstr1);
[C++]
public: static String* Concat(String* str0,String* str1);
[JScript]
public static function Concat(
str0 : String,str1 : String) : String;
パラメータ
戻り値
str0 と str1 の連結結果。
解説
Empty 文字列は、任意の null 引数の代わりに使用されます。
使用例
[Visual Basic, C#, C++] 個人の名前の、名、ミドル ネーム、姓を連結する方法については、次のコード例を参照してください。
Imports System
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,
' 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 'Main
End Class 'ConcatTest
[C#]
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 ) );
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
int main()
{
// we want to simply quickly add this person's name together
String* fName = S"Simon";
String* mName = S"Jake";
String* lName = S"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(S"Welcome to this page, '{0}'!", String::Concat(String::Concat(fName, mName), lName));
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
参照
String クラス | String メンバ | System 名前空間 | String.Concat オーバーロードの一覧 | Join