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

  • برمجة سي شارب
  • برمجة

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

الأجوبة

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);
	}
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...