快速提示 - 我对c#非常陌生,所以如果这很愚蠢,我很抱歉。用另一个字符替换字符串中的字符并切换回
我很难尝试在书中完成一个简单的c#任务。
Pseudocode-
文本框中的文本=用户输入
,如果一个按钮被点击 有星号
人换掉在文本框中全部为大写字母,如果两个按钮被点击 更换星号与他们的原始字符(回到正常)
这是我到目前为止
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button1.Click += new System.EventHandler(ClickedButton);
button2.Click += new System.EventHandler(ClickedButton);
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void ClickedButton(object sender, EventArgs e)
{
string orignalText = textBox1.Text;
if (sender == button1)
{
string replaced = Regex.Replace(orignalText, @"[A-Z]", "*");
textBox1.Text = (replaced);
}
else if (sender == button2)
{
textBox1.Text = (orignalText);
}
}
}
}
问题是button2显示带星号的文本。它应该显示(我希望它显示)原始字符。
谢谢亚历山大! –