Write a C# program to copy one string to another string

Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..

using System;
public class StringExercise
{
    public static void Main()
    {
        string str1;
        int i, length;
 
        Console.Write("Enter the string : ");
        str1 = Console.ReadLine();
 
        length = str1.Length;
        string[] str2 = new string[length];
 
        /* Copies string1 to string2 character by character */
        i = 0;
        while (i < length)
        {
            string tmp = str1[i].ToString();
            str2[i] = tmp;
            i++;
        }
        Console.Write("\nThe First string is : {0}\n", str1);
        Console.Write("The Second string is : {0}\n", string.Join("", str2));
        Console.Write("Number of characters copied : {0}\n\n", i);
 
        Console.ReadLine();
    }
}

Result

Write a C# program to copy one string to another string
Write a C# program to copy one string to another string

Leave a Comment

x