C# Sharp Exercises: Copy one string into another string
C# Sharp String: Exercise-8 with Solution
Write a program in C# Sharp to copy one string to another string.
Sample Solution:-
C# Sharp Code:
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);
}
}
Sample Output:
Copy one string into another string : ----------------------------------------- Input the string : w3resource.com The First string is : w3resource.com The Second string is : w3resource.com Number of characters copied : 14
Flowchart:
C# Sharp Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a program in C# Sharp to count a total number of alphabets, digits and special characters in a string.
Next: Write a program in C# Sharp to count a total number of vowel or consonant in a string.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework