c# - 字符洗牌器

标签 c# .net asp.net char shuffle

我只是想知道是否有一种方法(使用 ASP.NET C#)来“打乱”字符串的内容,但仍然能够单击另一个按钮并将其“取消打乱”回到其原始内容而不保存原创内容?

谢谢你:)

例子:

"This is not shuffled."

"isuo .tffsnl iTh shed"

...And then I click the "UNShuffle" button and it becomes normal again:

"This is not shuffled."

最佳答案

这很容易:

var rnd = new Random();
string unsuffled = "This is not shuffled.";
string shuffled = new string(unsuffled.OrderBy(r => rnd.Next()).ToArray());

但由于它是随机的,除非您存储之前的字符串或映射,否则您无法取消洗牌。

关于c# - 字符洗牌器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3226877/

相关文章:

javascript - 从 Javascript 调用方法

c# - Web 服务 API 提供多个要下载/保存的 csv 文件

c# - 检查 session 是否为空

c# - 如何获得指向 C 函数的指针?

c# - lambda 中的自定义相交

c# - 排除 'Else' 子句是否有性能差异?

c# - 默认情况下,F# 中的引用是否不可为空?

c# - F# 动态对象访问

c# - 在 EF Core 中设置属性约定?

.net - 转换和拆箱有什么区别?