Export (0) Print
Expand All

String.Concat Method (String, String)

.NET Framework 1.1

Concatenates two specified instances of String.

[Visual Basic]
Overloads Public Shared Function Concat( _
   ByVal str0 As String, _
   ByVal str1 As String _
) As String
[C#]
public static string Concat(
 string str0,
 string str1
);
[C++]
public: static String* Concat(
 String* str0,
 String* str1
);
[JScript]
public static function Concat(
   str0 : String,
 str1 : String
) : String;

Parameters

str0
The first String.
str1
The second String.

Return Value

The concatenation of str0 and str1.

Remarks

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

Example

[Visual Basic, C#, C++] The following code example concatenates a person's first, middle, and last name.

[Visual Basic] 
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] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

String Class | String Members | System Namespace | String.Concat Overload List | Join

Show:
© 2014 Microsoft