2012-10-27 69 views
-1

我怎樣才能把它...如何刪除「 - 」從文本

 static int count = 0; 
    string s; 
    private void SetClock_Click(object sender, EventArgs e) 
     { 
      count++; 
      label5.Text = count.ToString("X2"); 
      DateTime time = DateTime.Now; 
      s = "4D-" + "1A-" + "2B-" + "3C-" +(label5.Text); 
      txtSend.Text = s; 
     } 

我怎樣才能獲得文本從「S」當我按下另一個按鈕,看看它在另一個文本框,但沒有「 - 」 我的意思是:

s= 4D-1A-2B-3C-label5.text 

我希望它在另一個文本框中按下按鈕來查看:

4D 1A 2B 3C label5.text 

謝謝!

回答

7

不是很辛苦:

myOtherTextbox.Text = s.Replace('-', ' '); 
2

假設你的兩個文本框是相同的形式,如果你想,當你按下另一個按鈕,待更新的第二個文本框,那麼這會爲你

private void AnotherButton_Click(object sender, EventArgs e) 
{ 
    txtAnotherTextBox.Text = txtSend.Text.Replace('-', ' '); 
} 

,並請,如果你真的需要共享的形式事件之間的s變量,給它一個有意義的名字

0

連接按鈕事件ŧ o你的另一個按鈕,「txtAnotherTextBox」是你的另一個文本框。並且在你的情況下,變量's'被全局聲明,你可以使用它。

private void anotherButton__Click(object sender, EventArgs e) 
{ 
txtAnotherTextBox.Text = s.Replace('-', ' '); 
} 
0

而是寫

txtSend.Text = s; 
在你的代碼寫

的:

txtSend.Text = s.Replace("-"," "); 

要不然去Regex.Replace()去雖然這link獲取更多信息。