有点卡在弦上! [英] a little stuck on strings!
问题描述
嘿人们...
我真的对C#不太好,这几乎是我的第一个裂纹,我很喜欢...但是我很执着,如果可以的话,我将非常感谢您的帮助
我想从textbox1中获取一个字符串,然后单击按钮,将此文本发送到textbox1中最初在字符串中的其他每个字符之后的"x"文本.
换句话说,文本框1会显示这是一个字符串",然后在按钮blick上,文本框2会显示为2 ="txhxixs xixs xa xsxtxrxixnxg",这似乎有些愚蠢,但它是用于将数据写入com端口的,但是输出理论将是相同的...
就像这样:
Hey people...
I''m really not very good with c#, this is pretty much my first crack and I like it...but i''m pretty stuck and would really appreciate some help if you could
I''d like to get a string from textbox1, then on button click, send this text to textbox2 with ''x'' after every other character in the string originally in textbox1.
In other words, textbox 1 would read "this is a string", then on button blick, textbox 2 would read 2= "txhxixs xixs xa xsxtxrxixnxg" it may seem a little daft but its for writing data to a com port, but the output theory would be the same...
So something like:
private void button1_Click(object sender, System.EventArgs e)
{
char[] inputtext = textBox1.Text.ToCharArray()
string letterx = ((char)120).ToString();
for (int i = 0,i<inputtext.length;i++)>
{
textBox2.Text = (inputtext, i, 0); //***
Thread.Sleep(200);
textBox2.Text = (letterx.ToString());
Thread.Sleep(200);
}
}
到目前为止,我一直在使用serialPort1.Write(inputtext2, i, 1)
写入com端口,但这似乎只发送一个字符
我真的很希望你们能提供的任何帮助
欢呼声,
M
So far i''ve been writing to the com port using serialPort1.Write(inputtext2, i, 1)
, but this only seems to send a single character
i''d really appriciate any help you guys could give
cheers,
M
推荐答案
我不了解写入COM端口的位置或为什么使用Thread.Sleep()?
I don''t understand where the writing to com port comes in or why you are using Thread.Sleep()?
StringBuilder sb = new StringBuilder();
foreach(Char c in textBox1.Text)
{
sb.Append(c);
if(!Char.IsWhiteSpace(c))
{
sb.Append("x");
}
}
textBox2.Text = sb.ToString();
嘿向导感谢您的回复...它带来了大量错误,与lamda转换有关( ??)
和嗨马克.基本上,对于一个小型的uni项目,我已经构建了带有LCD控制器的蓝牙寻呼机.它长而纤细的是bt控制器,它接收从comp端口发送的字符,并使用该数据来控制LCD驱动器.
我已对硬件进行了编码,以便在从com端口接收到字符时作出响应,但随后在指令之间必须接收到字符"x",才能接收到有效的端口信号.
一切工作正常,但是我一次只能在C#应用程序中输入1个字符...因此,我需要分解一个字符串,在每个第二个字符中添加x并发送它,这是有道理的. ?
hey wizzard thanks for the reply...it comes up with a loads of errors, something to do with lamda conversion (??)
and Hi mark. Basically for a small uni project i''ve built a bluetooth pager with an LCD controller. The long and skinny of it is a bt controller recieves a character sent from a comp port and uses that data to control an LCD driver.
I have coded the hardware to respond when a character is recieved from a com port, but then the character ''x'' must be recieved between instructions for a valid port signal to be recieved.
Everything is working well, But i can only enter 1 character at a time into my C# application...hence the reason I need to break down a string, add x to every second character and send it...does that make any sense?
嗯,尝试:
Hmm, try:
textBox2.Text += (inputtext, i, 0);
Thread.Sleep(200);
textBox2.Text += (letterx.ToString());
Thread.Sleep(200);
这篇关于有点卡在弦上!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!