.NET Framework Class Library
String..::.Concat Method (String, String)

Concatenates two specified instances of String.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
Syntax

Visual Basic (Declaration)
Public Shared Function Concat ( _
    str0 As String, _
    str1 As String _
) As String
Visual Basic (Usage)
Dim str0 As String
Dim str1 As String
Dim returnValue As String

returnValue = String.Concat(str0, str1)
C#
public static string Concat(
    string str0,
    string str1
)
Visual C++
public:
static String^ Concat(
    String^ str0, 
    String^ str1
)
JScript
public static function Concat(
    str0 : String, 
    str1 : String
) : String

Parameters

str0
Type: System..::.String
The first String.
str1
Type: System..::.String
The second String.

Return Value

Type: System..::.String
The concatenation of str0 and str1.
Remarks

An Empty string is used in place of any null argument.

Examples

The following example concatenates a person's first, middle, and last name.

Visual Basic
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 and 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 
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 ) );
    }
}
Visual C++
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 ) );
}

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
See Also

Reference

Tags :


Page view tracker