c# - 每次按下按钮时,如何从字符串的前面连续移动n个字符到末尾?

标签 c# string winforms

每次按下按钮时,我都试图将字符串的第一个字符移到末尾。

我的逻辑似乎只在我按下按钮后一次又一次地显示第一个输出。

string input = "";
string manipulated = "";
int initial;

input = txtInput.Text;

if (txtInput.Text == String.Empty)
{
    MessageBox.Show("Textbox is empty, please input a string.");
}
else 
{
        for (initial = 1; initial < input.Length; initial++)
        {
            manipulated += input[initial];
        }
        manipulated += input[0];
        lblOutput.Text = manipulated.ToString();
        input = manipulated;
        manipulated = "";
}

例如如果我在文本框中输入“1234”并按下按钮,我的输出应该是“2341”,然后在我再次按下按钮后,输出应该移动到“3412”..等等。

最佳答案

这是基本字符串操作的一个简单示例:

private void ManipulateBtn_Click(object sender, EventArgs e)
    {
        string input = InputTxt.Text; // Read the text from you Textbox in Windos form
        if (input == string.Empty)
        {
            return;
        }
        string temp = input[0].ToString(); // Create a temp for the first char(toString) from you input
        input = input.Remove(0,1); // Remove (from you input) At Index 0 (the idex from fist char in string) 1 time) 
        input += temp; //add the firs item from you input at the end of string
        InputTxt.Text = input; // prin the result in the Textbox back.
    }

可以看例子SimpleStringOperation

关于c# - 每次按下按钮时,如何从字符串的前面连续移动n个字符到末尾?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56301414/

相关文章:

c# - 从自定义对话框中获取 DialogResult

c# - 在这个函数中放在哪里等待?

c# - Sitecore 路径分析器 : System. InvalidOperationException:此 SqlTransaction 已完成;它不再可用

javascript - 如何用 ) 或 = 拆分 JS 字符串?

c++ - 我可以从 nullptr 构造一个 string_view 吗?

c# - 如何对 BindingList<T> 进行排序?

c# - 遍历 GridView 行并单独设置图像

c# - 在 .net 中针对来自 visual studio 测试客户端的不同机器对 WCF 进行单元和性能测试的最佳方法是什么

c# - 如何返回与给定字符串匹配的枚举值?

javascript - 比较忽略特殊字符 "ä"的 JavaScript 字符串