我有以下字符串:
21>请具体说明.你是什么意思?21>你好,那里623>西蒙?
我想把它分成:
21>Please be specific. What do you mean by that?
21>Hello are you there
623>Simon?
Run Code Online (Sandbox Code Playgroud)
基本上,拆分器是数值(在这种情况下为21和623),后跟>
.
我的实现是我找到了>
char,然后向后走,直到找到非数字值.
所以基本上使用sub-string
等.但它很难看,而且我确信有更好的Regex实现,但我对此并不了解.
那么可以在这里使用正则表达式吗?
我有以下代码:
<div class="citation">
<span>some text
<span id="innerSpan">inner text</span>
some more text
</span>
</div>
Run Code Online (Sandbox Code Playgroud)
我试图用citation
类来影响div的外跨度,但不是内部跨度:
.citation {
color:red;
}
.citation span {
color: yellow
}
Run Code Online (Sandbox Code Playgroud)
我试过了:第一个类型,:nth-child,但似乎没什么用.
我进行以下测试,以查看该defer
属性是否推迟脚本块的执行。有2个脚本块。第一个带有defer
属性,第二个带有out。如果我正确理解,则该属性会强制浏览器在所有html解析完成后(包括其他script
块)。
但是从控制台来看,我始终是“从推迟开始”的。这是为什么?defer
在本script
地块上不起作用?
<html>
<body>
...
<script type="text/javascript" defer>
console.log('from deferred');
</script>
<script type="text/javascript">
console.log('from regular');
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我有一个异步方法,它调用另一个异步方法,但是,我希望它在单独的线程上并行运行:
public async Task<Page> ServePage() {
Task.Run(() => DoThings(10)); // warning here
// ... other code
return new Page();
}
public async Task DoThings(int foo) {
// stuff
}
Run Code Online (Sandbox Code Playgroud)
警告指出:
由于不等待此调用,因此在调用完成之前将继续执行当前方法。考虑将“await”运算符应用于调用结果。
事实上,这就是我正在努力做的事情。为什么我会收到编译器警告?Task.Run 的语法是否不正确?
.NET Core具有以下签名的方法:
.Replace(string old, string @new, StringComparison comp)
Run Code Online (Sandbox Code Playgroud)
.NET Standard仅具有此方法。
.Replace(string old, string @new)
Run Code Online (Sandbox Code Playgroud)
能够在Web项目中而不是在引用的库项目中使用它的.NET Core版本感觉很奇怪。
我怀疑我的问题的答案是否定的,但想确定。
我有一个 DATETIME 变量@DateEnd = '1/4/2011 16:43:22 PM'
。我想得到一天的结束:1/4/2011 23:59:59.997
。
我有以下内容并且工作正常,但它有很多转换并且似乎效率不高:
DECLARE @DateString VARCHAR(25)
DECLARE @DateEnd DATETIME = '1/4/2011 16:43:22 PM'
SET @DateString = CONVERT(VARCHAR(10), @DateEnd, 101) + ' 23:59:59.997'
SET @DateEnd = CAST(DateString AS DATETIME)
Run Code Online (Sandbox Code Playgroud)
有没有更有效的方法来实现这一目标?
我正在尝试将 VB.NET 代码转换为 C#。我有以下内容:
If IsDataProperty(p) And (p.Name.StartsWith("ref_") = False) Then
...
Run Code Online (Sandbox Code Playgroud)
如果我使用反编译器查看 C# 版本的样子,我会得到以下结果:
if (this.IsDataProperty(p) & !p.Name.StartsWith("ref_")) {
...
Run Code Online (Sandbox Code Playgroud)
VB中的运算符AND
编译为&
C#运算符。
代码不应该与&&
运算符一起使用吗:
if (this.IsDataProperty(p) && !p.Name.StartsWith("ref_")) {
...
Run Code Online (Sandbox Code Playgroud)
从逻辑上讲,在VB代码中,如果IsDataProperty(p)
为假,则整个语句将为假。
我有一个 Windows 服务。在启动时,它会检查是否有任何工作分配给它——如果没有,它就会退出。问题是恢复机制设置为重启服务。
如果服务合法崩溃,这就是我想要的,但如果我自己以编程方式退出服务,则不是。
到目前为止,我在下面尝试的所有操作都导致 Windows 自动重新启动服务:
Thread th;
protected override void OnStart(string[] args)
{
th = new Thread(new ThreadStart(StartMyService));
th.Start();
}
private void StartMyService()
{
if (WorkAvailable()) {
InitWork();
} else {
this.ExitCode = 0; // no errors
Stop();
}
}
protected override void OnStop()
{
// dispose of things
try
{
if (th != null && th.ThreadState == ThreadState.Running)
th.Abort();
}
catch { }
Environment.Exit(this.ExitCode);
}
Run Code Online (Sandbox Code Playgroud)
我尝试了不同的 ExitCode 值,但 Windows 总是重新启动服务。我也试过Environment.FailFast
同样的结果。我错过了什么?
在下面的:
string input = "123";
char [] separators = " ".ToCharArray();
string [] elements = input.Split(separators);
Run Code Online (Sandbox Code Playgroud)
该elements
阵列是.长度= 1.
这是为什么?String 123
不包含任何空格.
Javascript:
function bounds(a, b, c) {
null != b && (a = Math.max(a, b));
null != c && (a = Math.min(a, c));
return a
}
Run Code Online (Sandbox Code Playgroud)
老实说,我什至不知道这里发生了什么。如果b
不为null,则a
设置set Math.max(a, b)
。如果c
不为null,a
则从设置Math.min(a, c)
?
如何将其转换为C#?
PS:这是我的翻译。它是否正确?
private double bounds(double a, double? b, double? c) {
if (b != null) a = Math.Max(a, b.Value);
if (c != null) a = Math.Min(a, c.Value);
return a;
}
Run Code Online (Sandbox Code Playgroud) c# ×8
.net ×4
.net-core ×2
javascript ×2
async-await ×1
css ×1
html ×1
regex ×1
sql ×1
sql-server ×1
vb.net ×1
windows ×1