小编obd*_*dgy的帖子

读多线程的大txt文件?

我有100000行的大型txt文件.我需要启动n-count个线程并从该文件中为每个线程提供uniq行.做这个的最好方式是什么?我想我需要逐行读取文件,迭代器必须是全局的才能锁定它.将txt文件加载到列表将非常耗时,我可以收到OutofMemory异常.有任何想法吗?用一些代码帮助plz.

c#

22
推荐指数
4
解决办法
2万
查看次数

用动态数字替换文本中的单词/值

对于前者 我有字符串

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)

c# replace

4
推荐指数
1
解决办法
288
查看次数

兰德的问题

我有这样的代码:字符串文本中有一些{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个相同的字符串.为什么?

c#

2
推荐指数
2
解决办法
254
查看次数

寻找第一个空间的正则表达式问题

我有这样的台词:

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

但它不是我需要的工作方式.

notepad++

1
推荐指数
1
解决办法
3432
查看次数

将txt文件转换为字典<string,string>

我有一个文本文件,我需要将所有偶数行放到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)

c# dictionary file

0
推荐指数
1
解决办法
1万
查看次数

如何在foreach中重复一个循环

大家好,你怎么能在 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)

怎么做?

c# for-loop

0
推荐指数
1
解决办法
6709
查看次数

标签 统计

c# ×5

dictionary ×1

file ×1

for-loop ×1

notepad++ ×1

replace ×1