c# - 需要打乱选定的文本

标签 c#

    protected void Button_Upload_Click(object sender, EventArgs e)
    {
        string path = Server.MapPath("~/Data/" + FileUpload1.FileName);
        string[] readtext = File.ReadAllLines(path);
        var a = readtext;
        List<string> strList = new List<string>();
         foreach (string s in readtext)
        {
            strList.Add(s);
        }
        ListBox1.DataSource = strList;
        ListBox1.DataBind();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        var b = ListBox1.SelectedIndex;
        var a = ListBox1.SelectedValue.ToString();
        if (b < 0)
        {
            // no ListBox item selected;
            return;
        }

           StringBuilder jumbleSB = new StringBuilder();
            jumbleSB.Append(a);
            Random rand = new Random();
            int lengthSB = jumbleSB.Length;
            for (int i = 0; i < lengthSB; ++i)
            {
                int index1 = (rand.Next() % lengthSB);
                int index2 = (rand.Next() % lengthSB);
                Char temp = jumbleSB[index1];
                jumbleSB[index1] = jumbleSB[index2];
                jumbleSB[index2] = temp;

            }

            Console.WriteLine(jumbleSB);

            TextBox1.Text = ListBox1.Text.ToString();
            //TextBox1.Text = ListBox1.Text.Insert(jumbleSB);

这里我需要混淆用户选择的值。当用户选择一个值时,它必须困惑并且必须进入文本框。我无法显示 Jumble 值。任何帮助请...?

最佳答案

Console.WriteLine(jumbleSB.ToString());

关于c# - 需要打乱选定的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36147338/

相关文章:

c# - 如何向私有(private)构造函数注入(inject)依赖?

c# - 想要在 itextSharp 的最后一页上删除页脚

c# - 如何在数据库中存储稀疏 bool 向量?

C# 自定义 Setter 事件或继承的 Setter

c# - GroupBy 从 IEnumerable 对象列表中删除重复项

c# - 如何实现线程安全列表?

c# - C# 向数据库中插入日期

c# - "Read only"C# 中的属性访问器

c# - MVC - 用于显示事件的 JQuery Datepicker

c# - Prism EventAggregator 订阅执行两次