im trying to replace normal text with ascii text in this program:
so a will be replaced by â & ETC.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TextConverter
{
public partial class TextCoverter : Form
{
public TextCoverter()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] normal = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
string[] ascii = { "â", "ß", "ç", "ð", "è", "ƒ", "ģ", "н", "ι", "j", "ќ", "ļ", "м", "и", "ю", "ρ", "Ω", "ѓ", "$", "τ", "ט", "Λ", "ш", "χ", "У", "ź" };
for (int i = 0; i < 26; i++)
{
textBox2.Text = textBox1.Text.Replace(normal[i], ascii[i]);
}
}
}
}
But it doesn’t replace with Ascii. Please help.
Since you are writing the result into a variable that is different from the original, only the last letter gets replaced. You should either write to the same box, or write to a temp string, and write it to the second box at the end.
Generally speaking, this is not the most efficient algorithm to do replacements, because it operates on an immutable string. You would be better off creating a mutable string builder, and writing it one character at a time.