小编Mic*_*eyn的帖子

查看手册页时,如何查看加载它的目录?(例如,用于确定本地共享与系统共享)?

我只是想弄清楚当前查看的手册页是从哪个绝对路径加载的 - 它的绝对路径文件名。

linux manpage

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

字符串的集合到字典

给定一个有序的字符串集合:

var strings = new string[] { "abc", "def", "def", "ghi", "ghi", "ghi", "klm" };
Run Code Online (Sandbox Code Playgroud)

使用LINQ创建字符串字典到集合中该字符串的出现次数:

IDictionary<string,int> stringToNumOccurrences = ...;
Run Code Online (Sandbox Code Playgroud)

最好一次通过琴弦收集......

c# linq c#-4.0

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

将默认资源样式应用于所有DataGridTextColumns

我有几个数字列,希望它们是正确的.这是一个有点人为的例子,展示了我的问题:

<Window x:Class="MyApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=PresentationFramework" xmlns:Windows="clr-namespace:System.Windows;assembly=PresentationFramework" xmlns:Data="clr-namespace:System.Windows.Data;assembly=PresentationFramework" Title="MyApp"
        Width="Auto" Height="Auto" SizeToContent="WidthAndHeight" Loaded="Window_Loaded">
  <Controls:DataGrid Name="MyDataGrid" IsReadOnly="True"
          xmlns="http://schemas.microsoft.com/wpf/2008/toolkit" ItemsSource="{Data:Binding}" AutoGenerateColumns="True">
    <Controls:DataGrid.Columns>
      <!-- This is a product name and is left justified by default -->
      <Controls:DataGridTextColumn Header="ProductName" Binding="{Data:Binding Path=ProductName}" />
      <!-- The rest of the columns are numeric and I would like for them to be right justified -->
      <Controls:DataGridTextColumn Header="ProductId1" Binding="{Data:Binding Path=ProductId1}" >
        <Controls:DataGridTextColumn.ElementStyle>
          <Windows:Style TargetType="Controls:TextBlock">
            <Windows:Setter Property="HorizontalAlignment" Value="Right"/>
          </Windows:Style>
        </Controls:DataGridTextColumn.ElementStyle>
      </Controls:DataGridTextColumn>
      <Controls:DataGridTextColumn Header="ProductId2" Binding="{Data:Binding Path=ProductId2}" >
        <Controls:DataGridTextColumn.ElementStyle>
          <Windows:Style TargetType="Controls:TextBlock">
            <Windows:Setter …
Run Code Online (Sandbox Code Playgroud)

c# wpf wpfdatagrid c#-4.0

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

将包含驱动器号的相对路径转换为.NET文件函数的绝对路径

如何将驱动器相对路径(如D:test.xml)转换为XDocument.Load()等函数将接受的绝对路径.例如,D驱动器可以将D:\ data作为其当前工作目录,因此D:test.xml将表示D:\ data\test.xml.我已经尝试过像D:.\ test.xml这样的混合.

这是我得到的类似D的错误:test.xml:无效的URI:Dos路径必须是root,例如'c:\'

.net c# .net-4.0 c#-4.0

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

SQL Server GROUP BY进退两难

我有一个表,其中的行包含一个名为的列MySubId.此列中的值可以重复.我想找到最多出现的值的MySubId值和行数MySubId.

我有以下查询:

SELECT MySubId, COUNT(MySubId) AS MySubIdCount
FROM MyTable
GROUP BY MySubId
HAVING COUNT(MySubId)=MAX(COUNT(MySubId))
Run Code Online (Sandbox Code Playgroud)

但我得到错误:

消息130,级别15,状态1,行4无法对包含聚合或子查询的表达式执行聚合函数.

用简单的查询不可能做到这一点吗?在HAVING子句中使用它之前,我是否必须嵌入子查询来计算MAX ?

更新:

我看到很多anwers通过使用过滤结果集TOP 1,所以我假设没有办法使用该MAX函数将此查询过滤到最大出现MySubId值?

sql t-sql sql-server-2008 sql-server-2008-r2

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

使用new动态分配字符是否需要编译器将它们初始化为零

例如:

char *p=new char[100];
Run Code Online (Sandbox Code Playgroud)

指向的字符数组必须p按照C++标准初始化为零吗?或者,这种行为完全依赖于编译器吗?

gcc似乎在每个字符上调用默认构造函数,当然这会将它们初始化为零.Visual C++ 2010没有.

c++ c++11

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

为什么_localtime32和_gmtime32为非GMT时区返回相同的时间值?

我的时区设置为CDT控制面板日期/时间小程序.

以下代码将完全相同的日期和时间放入pCurGmtTimepCurTime:

int main(int argc, char *argv[])
{
  __time32_t t=_time32(NULL);

  tm *pCurGmtTime=_gmtime32(&t);
  tm *pCurTime=_localtime32(&t);

  // The values in the *pCurGmtTime structure are equal to the values in *pCurTime

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

我没有TZ设置环境变量,但是通过"控制面板日期和时间"小程序为系统正确配置了我的时区.这种行为似乎违背了这些功能的MSDN文档,其中说这TZ会覆盖控制面板设置,但如果不存在,则将使用控制面板设置.

谢谢

c++ windows windows-server-2008-r2

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

我应该使用哪个类将二进制数据写入缓冲区(比如一个字节列表)

我想在缓冲区中将数据编码为二进制格式,稍后我将写入文件或通过套接字传输.C#类或类最适合用于创建List<byte>包含二进制数据的内容.

我将以自定义编码格式(对于字符串)存储整数,单字节字符串(即ASCII),浮点数和其他数据,以及用于整数和浮点类型的常规二进制数字布局.

BinaryWriter看起来它有我需要的方法,但它必须为我管理一个不断增长的缓冲区,我想List<byte>从我完成编码时产生一个结果.

谢谢

.net c# .net-4.0 c#-4.0

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

What is a performant way to split long lines when only a subset of fields is desired

The details of my query follow:

  1. I have a very large TSV (Tab Sep. Value) file (where large > 30 GB).
  2. I want to extract certain lines from this file that don't end with an empty last field. Since this is a TSV file, those lines that don't end with \t\n, which is a trivial test and not the subject of this question. That will remove some 75% of the lines, right off the bat, reducing the workload.
  3. Then …

csv perl text-parsing string-parsing perl5.30

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

如何将正则表达式中的单个匹配作为标量传递

我想将reg-ex的单个捕获作为标量传递给子程序,我该怎样做呢?这是一个例子:

sub myfunc($)
{
   my ($value)=@_;

   # Do something with $value...
}

# This is the data we want to parse
my $some_var='value: 12345'; # For example

# We want to extract the value '12345' from $some_var 
# and pass it to the myfunc subroutine as a scalar

# Attempt #1: This doesn't work    
myfunc($some_var=~/value: (\d+)/);

# Attempt #2: This does work, but seems overly complicated
myfunc(join('',$some_var=~/value: (\d+)/));
Run Code Online (Sandbox Code Playgroud)

有没有比尝试#2更好的方法?

更新:

Oesor的回答完全给出了我想要避免调用的内容join:

myfunc(($some_var=~/value: (\d+)/)[0]);
Run Code Online (Sandbox Code Playgroud)

regex perl

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