Q:

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

0

Write a program in C# Sharp to copy one string to another string. 
Test Data :
Input the string : This is a string to be copied.
Expected Output :

The First string is : This is a string to be copied. 

The Second string is : This is a string to be copied. 

Number of characters copied : 31

All Answers

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

using System;  
public class Exercise8  
{  
    public static void Main() 
{
    string str1;
    int  i,l;
      Console.Write("\n\nCopy one string into another string :\n");
      Console.Write("-----------------------------------------\n"); 	
      Console.Write("Input the string : ");
      str1 = Console.ReadLine();     
      l=str1.Length;
      string[] str2=new string[l];
    /* Copies string1 to string2 character by character */
    i=0;
    while(i<l)
    {
        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);
	}
}

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now