【问题标题】:C# How to replace multiple chars in string at the same time? [duplicate]C#如何同时替换字符串中的多个字符? [复制]
【发布时间】:2015-01-09 16:57:30
【问题描述】:

我有问题。我正在制作1337 7r4|\|5l4704 (leet speak translator),我希望有多个字符可以相互替换。

例如,我想在一个命令中将“A”和“a”替换为“4”。我有这样的事情:

    private void button1_Click(object sender, EventArgs e)
    {
        textBox2.Text = "";
        string a = textBox1.Text;
        string sr = a.Replace("A", "4");
        textBox2.Text = sr;
    }

我该怎么做?

【问题讨论】:

    标签: c# string replace char


    【解决方案1】:

    试试

    string sr = a.Replace('A', '4').Replace('a', '4');
    

    【讨论】:

    • 这没有提供问题的答案。要批评或要求作者澄清,请在其帖子下方发表评论。
    • OP 询问for example I want to replace "A" and "a" with "4" in one command,这是我的回答地址。除非您的意思是 Replace 菊花链表示多个命令。
    • 谢谢!帮了大忙!
    猜你喜欢
    • 2021-05-31
    • 2014-06-27
    • 2021-11-25
    • 1970-01-01
    • 1970-01-01
    • 2021-05-09
    • 2020-08-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多