【发布时间】:2014-08-25 11:50:08
【问题描述】:
如何将用户在文本框中输入的数据流式传输到int数组中?假设我有一个带有 2 个文本框、按钮和缓冲区的窗口,在界面中不可见。
我希望在单击button1 后将来自textbox1(例如CAT)的数据保存到int buffer[255]。然后,点击button2 后,CAT 应该会出现在textbox2 中,并且正在从buffer 中删除。
应该是这样的:
int buffer[255]={0};
//user entered 'CAT' in textbox1
//clicking button1
//now:
buffer[0]=[67]; //67 = 'C' in ASCII
buffer[1]=[65];
buffer[2]=[84];
//clicking button2
//in read-only textbox2 'CAT' appears
//now:
buffer[]={0};
我想在 textbox2 中显示单词时需要进行一些转换(for loop 和 System.Convert.ToChar(buffer[i])),但最让我困惑的是如何将文本从 textbox1 保存到 buffer。
好的,谢谢回复,现在我需要让我的按钮工作,但不知道为什么,我现在有了这个方法:
public int saveToBuffer(string text)
{
string txt = text;
int[] receivedBuffer = new int[255];
int count = 0;
//int i = 0;
foreach(char c in txt)
{
receivedBuffer[count] = c;
count++;
}
return receivedBuffer[255];
}
它将文本从 textbox1 返回到数组 receivedBuffer。我也有这个按钮:
private void saveToBufferButton_Click(object sender, EventArgs e)
{
}
我不知道该放什么 beetwen {} 让它工作。
【问题讨论】:
-
您可以循环遍历
textbox1.Text直到textbox1.Text.Length并将每个字符放入缓冲区索引中。
标签: c# c++ arrays visual-studio-2010