我有100000行的大型txt文件.我需要启动n-count个线程并从该文件中为每个线程提供uniq行.做这个的最好方式是什么?我想我需要逐行读取文件,迭代器必须是全局的才能锁定它.将txt文件加载到列表将非常耗时,我可以收到OutofMemory异常.有任何想法吗?用一些代码帮助plz.
对于前者 我有字符串
string text = @"Today is {Rand_num 15-22} day. {Rand_num 11-55} number of our trip.";
Run Code Online (Sandbox Code Playgroud)
我需要用兰特数替换每个Rand_num构造(在规定的数字15-22或11-55之间)
试过smth但不知道接下来该做什么
string text = @"Today is {Rand_num 15-22} day. {Rand_num 11-55} number of our trip.";
if (text.Contains("Rand_num"))
{
string groups1 = Regex.Match(text, @"{Rand_num (.+?)-(.+?)}").Groups[1].Value;
string groups2 = Regex.Match(text, @"{Rand_num (.+?)-(.+?)}").Groups[2].Value;
}
Run Code Online (Sandbox Code Playgroud) 我有这样的代码:字符串文本中有一些{AVATAR}
if (text.Contains("{AVATAR}"))
text = Regex.Replace(text, "{AVATAR}", m => rand_avatars());
public string rand_avatars()
{
string[] text = avatars.ToArray();
Random rand = new Random(DateTime.Now.Millisecond);
return text[rand.Next(text.Length)];
}
Run Code Online (Sandbox Code Playgroud)
但在更换后我从头像中收到2个相同的字符串.为什么?
我有这样的台词:
url.ru/?kluch word word word
url.ru/?2kluch word
url.ru/?2kluch word word
url.ru/?2kluch_word word-word
Run Code Online (Sandbox Code Playgroud)
我需要把| 在url和第一个空间之间.
试试这个:
查找:^(.+)\ s(.+)
替换为: $ 1 | $ 2
但它不是我需要的工作方式.
我有一个文本文件,我需要将所有偶数行放到Dictionary Key和所有偶数行到Dictionary Value.什么是我的问题的最佳解决方案?
int count_lines = 1;
Dictionary<string, string> stroka = new Dictionary<string, string>();
foreach (string line in ReadLineFromFile(readFile))
{
if (count_lines % 2 == 0)
{
stroka.Add Value
}
else
{
stroka.Add Key
}
count_lines++;
}
Run Code Online (Sandbox Code Playgroud) 大家好,你怎么能在 foreach 中重复一次迭代?
foreach (string line in File.ReadLines("file.txt"))
{
// now line == "account", next line == "account1"
if (line.Contains("a"))
//next loop take "account1";
else
// need to set that next loop will take line == "account" again
}
Run Code Online (Sandbox Code Playgroud)
怎么做?