c#循環(huán)左移字符示例
循環(huán)左移字符例如:abcde循環(huán)左移2個字符就是cdeab
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 循環(huán)左移
{
class Program
{
static string reverse( char[] char2, int i, int j)
{
for (int begin=i,end=j;begin < end; begin++, end--)
{
char temp = char2[begin];
char2[begin] = char2[end];
char2[end] = temp;
}
return new String(char2);
}
static string leftshift( string str,int i ,int j)
{
char[] char1 = str.ToCharArray();
reverse( char1,0,i-1);
reverse( char1,i,j-1);
reverse( char1, 0, j - 1);
return new String(char1);
}
static void Main(string[] args)
{
Console.WriteLine("請輸入一個字符串:");
string mystring = Convert.ToString(Console.ReadLine());
int length = mystring.Length;
Console.WriteLine("請輸入你要左移的位數(shù),不要超過字符串長度"+length);
int N = Convert.ToInt32(Console.ReadLine());
String str=leftshift(mystring, N, length);
Console.WriteLine(str);
Console.WriteLine();
Console.ReadKey();
}
}
}
相關(guān)文章
C# WinForm制作一個批量轉(zhuǎn)化文件格式的小工具
在生活中有時候會遇到批量轉(zhuǎn)換格式的需求,一個個點太麻煩了,一個能夠?qū)崿F(xiàn)批量文件格式轉(zhuǎn)換的工具非常有用,所以本文小編使用C# WinForm制作一個批量轉(zhuǎn)化文件格式的小工具,文中有具體實現(xiàn)代碼,需要的朋友可以參考下2023-11-11
C# WebApi Get請求方式傳遞實體參數(shù)的方法示例
這篇文章主要給大家介紹了關(guān)于C# WebApi Get請求方式傳遞實體參數(shù)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用C#具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧2019-04-04

