C# Sharp Exercises: Create a new string from a given string with the first character added at the front and back
C# Sharp Basic: Exercise-17 with Solution
Write a C# program to create a new string from a given string (length 1 or more ) with the first character added at the front and back.
Sample Solution:-
C# Sharp Code:
using System;
using System.Text;
public class Exercise17 {
static void Main(string[] args)
{
string str;
int l= 0;
Console.Write("Input a string : ");
str = Console.ReadLine();
if (str.Length>=1)
{
var s = str.Substring(0,1);
Console.WriteLine(s + str + s);
}
}
}
Sample Output:
Input a string : The quick brown fox jumps over the lazy dog. TThe quick brown fox jumps over the lazy dog.T
Flowchart:
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a C# program to create a new string from a given string where the first and last characters will change their positions
Next: Write a C# program to check two given integers and return true if one is negative and one is positive.
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