每次按下按钮时,如何将 n 个字符从字符串的前面连续移动到末尾? [英] How can move n characters from front of the string to the end continuously every time I press the button?
本文介绍了每次按下按钮时,如何将 n 个字符从字符串的前面连续移动到末尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每次按下按钮时,我都试图将字符串的第一个字符移到末尾.
I'm trying to move the first char of the string to the end every time I press the button.
我的逻辑似乎只在我按下按钮后一次又一次地显示第一个输出.
My logic seems to only display the first output again and again after I press the button.
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"......等
E.g. if I enter "1234" in the text box and press the button, my output should be "2341", then after I hit the button again, the output should move to "3412" .. etc.
推荐答案
这是 Basics String 操作的一个简单示例:
This is a simple example of Basics String operations:
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
这篇关于每次按下按钮时,如何将 n 个字符从字符串的前面连续移动到末尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文