How to concat 2 strings without using any inbuilt string functions?

String is a character array.Find the length of the first character array, and find the length of the second character array, using a loop concat both strings.

Sample C# code :

string variable1 = “String concat”;
string variable2 = “example.”;
int length1 = variable1.Length;
int length2 = variable2.Length;
char[] concat = new char[length1 + length2];
for (int i = 0; i < length1; i++)
{
concat[i] = variable1[i];
}
for (int i = 0; i < length2; i++)
{
concat[i + length1] = variable2[i];
}

One thought on “How to concat 2 strings without using any inbuilt string functions?

  1. Pep August 4, 2017 / 10:18 am

    Can’t we achieve it by simply using “+” operator?

Leave a Reply