随机播放文本文件中的行 [英] shuffle lines in the text file

查看:62
本文介绍了随机播放文本文件中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何对文本文件中的行进行混排?

How to shuffle the lines in a text file?

推荐答案

您可以将行读入字符串数组,然后对数组索引进行混排(最后写将数组返回到文件中.)
:)
You may read the lines into an array of strings and then shuffle the array indices (and finally write back the array into a file).
:)


这里有一些LINQ代码,如CPallini建议的那样显示了如何执行此操作:

Here''s some LINQ code that shows how to do this as CPallini suggested:

Random random = new Random();
File.WriteAllLines(fileName, File.ReadAllLines(fileName).OrderBy(s => random.Next()).ToArray());


这篇关于随机播放文本文件中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆