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..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2. public class StringExercise
  3. {
  4. public static void Main()
  5. {
  6. string str1;
  7. int i, length;
  8.  
  9. Console.Write("Enter the string : ");
  10. str1 = Console.ReadLine();
  11.  
  12. length = str1.Length;
  13. string[] str2 = new string[length];
  14.  
  15. /* Copies string1 to string2 character by character */
  16. i = 0;
  17. while (i < length)
  18. {
  19. string tmp = str1[i].ToString();
  20. str2[i] = tmp;
  21. i++;
  22. }
  23. Console.Write("\nThe First string is : {0}\n", str1);
  24. Console.Write("The Second string is : {0}\n", string.Join("", str2));
  25. Console.Write("Number of characters copied : {0}\n\n", i);
  26.  
  27. Console.ReadLine();
  28. }
  29. }

Result

C# language techstudy

     





Related Topics




Popular Posts