- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
String slicing in C# to rotate a string
Let’s say our string is −
var str = "welcome";
Use the substring() method and the following, if you want to rotate only some characters. Here, we are rotating only 2 characters −
var res = str.Substring(1, str.Length - 1) + str.Substring(0, 2);
The following is the complete code −
Example
using System; public class Program { public static void Main() { var str = "welcome"; Console.WriteLine("Original String = "+str); var res = str.Substring(1, str.Length - 1) + str.Substring(0, 2); Console.WriteLine("Rotating two characters in the String: "+res); } }
Output
Original String = welcome Rotating two characters in the String: elcomewe
Advertisements
To Continue Learning Please Login
Login with Google