提示:用Substring分割字符串来做

class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("输入字符串");
            string str = Console.ReadLine();//从控制台获取输入字符串
            Console.WriteLine("输入偏移量");
            try
            {
                int b = int.Parse(Console.ReadLine());
                //计算真正的偏移量_bit
                int _bit = b % str.Length;

                string s1 = str.Substring(str.Length-_bit);//从字符串当前位取值到最后
                string s2 = str.Substring(0,str.Length-_bit);//从第0位取值,共str.Length-_bit个
                Console.WriteLine(s1+s2);//输出偏移后的
            }
            catch (Exception)
            {

                Console.WriteLine("输入有误");
            }
            Console.ReadLine();
            
        }
    }

 

相关文章:

  • 2021-10-22
  • 2022-12-23
  • 2021-11-08
  • 2021-04-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-28
  • 2021-12-17
  • 2021-11-15
  • 2022-01-10
  • 2021-06-06
  • 2021-10-08
相关资源
相似解决方案