每次按下按钮时,我都试图将字符串的第一个字符移到末尾。
我的逻辑似乎只在我按下按钮后一次又一次地显示第一个输出。
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.
}
关于c# - 每次按下按钮时,如何从字符串的前面连续移动n个字符到末尾?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56301414/