Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
LeftAndRightShiftStrings
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Text; namespace Rextester { public class Program { public static void Main(string[] args) { String str = "Hello world!"; leftshift(str,3); rightshift(str,3); } public static void leftshift(String str, int n) { StringBuilder sb = new StringBuilder(); String temp = reverse(str.Substring(0,n)); sb.Append(str.Substring(n-1,str.Length-n)+ temp.ToString()); Console.WriteLine("Left shifted " +sb.ToString()); } public static void rightshift(String str, int n) { StringBuilder sb = new StringBuilder(); String temp = reverse(str.Substring(str.Length-n,n)); sb.Append(temp.ToString() + str.Substring(0,str.Length-n)); Console.WriteLine("Right shifted " + sb.ToString()); } public static String reverse(String st) { StringBuilder sb = new StringBuilder(); int i=0; for(i= st.Length-1; i>=0; i--) { sb.Append(st[i]); } return sb.ToString(); } } }
run
|
edit
|
history
|
help
0
FromBibleC#(OOP)
Classes, properties, methods, ling begining
Enumeration
Count the number of capital letters, small letters, digits, spaces and special characters.
Ty
My name
Merge Sort
dairkoos
Fff
sfe