A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a C# program to copy one string to another string
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)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now