Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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);
  }
}


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
Posted
Updated 12-Jan-11 8:11am
v3

I don't understand where the writing to com port comes in or why you are using Thread.Sleep()?

C#
StringBuilder sb = new StringBuilder();
foreach(Char c in textBox1.Text)
{
    sb.Append(c);
    if(!Char.IsWhiteSpace(c))
    {
        sb.Append("x");
    }
}
textBox2.Text = sb.ToString();
 
Share this answer
 
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?
 
Share this answer
 
Comments
wizardzz 12-Jan-11 15:49pm    
Just a heads up, you should reply to the individual answers and not post this as a new answer.

So you're using the x as a delimiter or something? Will behavior be impacted where ever you are sending this if 'x' is the character inputted?
Hmm, try:

MIDL
textBox2.Text += (inputtext, i, 0);
Thread.Sleep(200);
textBox2.Text += (letterx.ToString());
Thread.Sleep(200);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900