Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Concat Method (String, String)

String.Concat Method (String, String)

Concatenates two specified instances of String.

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

public static string Concat (
	string str0,
	string str1
)
public static String Concat (
	String str0, 
	String str1
)
public static function Concat (
	str0 : String, 
	str1 : String
) : String
Not applicable.

Parameters

str0

The first String.

str1

The second String.

Return Value

The concatenation of str0 and str1.

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

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

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 ) );
    }
}

import System.*;

public class ConcatTest
{
    public static void main(String[] args)
    {
        // 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));
    } //main
} //ConcatTest

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2015 Microsoft