请帮我解决这个问题。我有一个巨大的input.txt。现在是 465 Mb,但以后至少会是 1Gb。
用户输入一个术语(不是整个单词)。使用该术语,我需要找到包含它的单词,将其放在<strong>标签之间并将内容保存到 output.txt。术语搜索应不区分大小写。
这是我到目前为止所拥有的。它适用于小文本,但不适用于大文本。
Regex regex = new Regex(" ");
string text = File.ReadAllText("input.txt");
Console.WriteLine("Please, enter a term to search for");
string term = Console.ReadLine();
string[] w = regex.Split(text);
for (int i = 0; i < w.Length; i++)
{
if (Processor.Contains(w[i], term, StringComparison.OrdinalIgnoreCase))
{
w[i] = @"<strong>" + w[i] + @"</string>";
}
}
string result = null;
result = string.Join(" ", w);
File.WriteAllText("output.txt", result);
Run Code Online (Sandbox Code Playgroud) 我跑了
File.Move(@"C:\sub1\file.xml", "file" + ".XMl"));
该文件确实消失了C:\sub1.没有抛出任何错误.文件到了哪里?
谷歌没有帮助我,所以也没有.
var timer = new System.Timers.Timer(5000);
timer.Elapsed += BreakEvent;
timer.Enabled = true;
Parallel.ForEach<string>(fileNames, (fileName, state) =>
{
try
{
ProcessFile(fileName);
}
catch (Exception)
{
}
finally
{
}
});
Run Code Online (Sandbox Code Playgroud)
我想ForEach在5秒(in BreakEvent)之后打破这个循环.
当然它可以是一个按钮或任何东西.
我知道破坏(在我的例子中)
state.Stop();
Run Code Online (Sandbox Code Playgroud)
但它仍然在循环中.
它甚至可能吗?
编辑:
对于那些搜索到其他方式的人来说,我就是这样的:
var timer = new System.Timers.Timer(5000);
timer.Elapsed += new System.Timers.ElapsedEventHandler((obj, args) =>
{
state.Stop();
});
timer.Enabled = true;
Run Code Online (Sandbox Code Playgroud) 我曾尝试乘为数字,即10000与10000 + 1通过C程序.但我没有得到正确的输出.
printf("%lld",(100000)*(100001));
Run Code Online (Sandbox Code Playgroud)
我已经在不同的编译器上尝试了上面的代码但是我得到了相同1410165408而不是10000100000.
假设我List<T>有一个名为Oddstype 的属性decimal,我怎样才能得到金额的乘法?
通常为了精心制作,Sum我做了类似这样的事情:
decimal amount = myList.Sum(x => x.Odds);
Run Code Online (Sandbox Code Playgroud)
但是我找不到允许我得到乘法的任何属性.linq不可能吗?
谢谢.
我从soap服务获取数据,并想知道在嵌套列表中提取第一个元素的正确方法
我遇到的问题的例子
tempModel.Value = req.Data
.FirstOrDefault()
.Readings
.FirstOrDefault()
.Extract
.FirstOrDefault()
.Values
.FirstOrDefault()
.Reading;
Run Code Online (Sandbox Code Playgroud)
事情是服务返回元素列表,我需要提取多个嵌套层中的每个内部的第一个元素.
如果有任何列表,这里的代码将给我异常.null
我知道我可以尝试捕获,但我有五个这些元素,我想填充视图模型.我正在努力寻找这个问题的干净解决方案,因为我理解我怎么能以"丑陋的方式"来做到这一点.
任何指针都将非常感激.
我需要从第二行string开始'\r'直到下一个'\r'字符.
这是我的字符串中的一个考试
string str = "@b\r210.190\r\000.000\r\n";
Run Code Online (Sandbox Code Playgroud)
我需要取值210.190但内部没有 '\r'字符.
我有一个从Cpp程序获取的字节数组。
arr[0..3] // a real32,
arr[4] // a uint8,
Run Code Online (Sandbox Code Playgroud)
我怎么解释arr[4]为int?
(uint)arr[4] // Err: can't implicitly convert string to int.
BitConverter.ToUint16(arr[4]) // Err: Invalid argument.
buff[0+4] as int // Err: must be reference or nullable type
Run Code Online (Sandbox Code Playgroud)
我是否必须将连续字节清零才能将其解释为UInt16?
好,这是混乱。最初,我定义了我的课程。
byte[] buff;
buff = getSerialBuffer();
public class Reading{
public string scale_id;
public string measure;
public int measure_revised;
public float wt;
}
rd = new Reading();
// !! here is the confusion... !!
// Err: Can't …Run Code Online (Sandbox Code Playgroud) 我正在编写一些代码,但发现当我创建不带setter的新抽象属性时,无法在构造函数中设置其值。当我们使用普通属性时,为什么可能这样?有什么不同?
protected Motorcycle(int horsePower, double cubicCentimeters)
{
this.HorsePower = horsePower; //cannot be assigned to -- it is read only
this.CubicCentimeters = cubicCentimeters;
}
public abstract int HorsePower { get; }
public double CubicCentimeters { get; }
Run Code Online (Sandbox Code Playgroud)
显然,如果要在构造函数中进行设置,则应使用受保护的设置器或公共设置器。
c# ×9
.net ×1
.net-3.5 ×1
abstract ×1
bytebuffer ×1
c ×1
char ×1
io ×1
linq ×1
multiplying ×1
properties ×1
python ×1
string ×1
text ×1
uint8t ×1