Q:
C# program to reverse a given string without using the predefined method
belongs to collection: C# Basic Programs | String programs
C# Basic Programs | String programs
- Comparing two strings in C#
- Demonstrate the example of Copy method of String class in C#
- Demonstrate the example of IndexOf() method of string class in C#
- Compare strings using Equals() method in C#
- Explain LastIndexOf() method of String class with Example in C#
- Explain String.Split() method of String class in C# with an Example
- How to convert string into uppercase in C#?
- How to convert string into lowercase in C#?
- How to get substring from a string in C#?
- How to trim the string in C#, an example of String.Trim() method?
- How to trim leading spaces of string using String.TrimStart() in C#?
- How to trim trailing spaces of string using String.TrimEnd() in C#?
- How to pad string from left using String.PadLeft() in C#?
- How to pad string from right using String.PadRight() in C#?
- Check whether string ends with given substring or not using String.EndsWith() in C#?
- How to remove given substring from a string using String.Remove() in C#?
- How to replace a character with another character in a string in C#?
- C# program to count the frequency of the specified word in the given string
- C# program to trim a specified string
- C# program to trim a specified string from the left side
- C# program to trim a specified string from the right side
- C# program to split a string using the Split() method of String class
- C# program to extract only numbers from a specified string using the Split() method
- C# program to get the length of the string
- C# program to replace a substring within a specified string
- C# program to find the occurrence of the specified word in a given string
- C# program to convert a string from lowercase to uppercase
- C# program to print the abbreviation of a given string
- C# program to print the list of all possible substrings of a specified string
- C# program to count the total number of digits in an alpha-numeric string
- C# program to concatenate the two strings using a predefined method
- C# program to reverse a given string without using the predefined method
- C# program to perform left padding without using PadLeft() method
- C# program to perform the right padding without using the PadRight() method
- C# program to count the total number of vowels in a given string
- C# program to generate random strings
- C# program to encrypt and decrypt a string using Rijndael key algorithm
- C# program to count the lines in a given string
Program:
The source code to reverse a given string without using the predefined method is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
Here, we created two static methods StrReverse() and Main(). The StrReverse() method is used to reverse a specified string, here we find the length of the string then access character from last to the start of the string and append each character to another string "reverse". At the end string "reverse" contains the reverse value of the given string that will be returned to the calling method.
Now look to the Main() method, In the Main() method, we read the value of the string and passed to the StrReverse() method that returned the reverse of the string and then finally prints the result on the console screen.