Q:

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

0

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

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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:

Enter the string : tech study

The First string is : tech study

The Second string is : tech study

Number of characters copied : 10

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a C# program to count a total number of vowe... >>
<< Write a C# program to print individual characters ...