小编its*_*lur的帖子

正则表达式拆分字符串保留引号

我需要根据空格作为分隔符拆分下面的字符串.但是应该保留引用中的任何空格.

research library "not available" author:"Bernard Shaw"
Run Code Online (Sandbox Code Playgroud)

research
library
"not available"
author:"Bernard Shaw"
Run Code Online (Sandbox Code Playgroud)

我试图在C Sharp中做到这一点,我有这个正则表达式:@"(?<="")|\w[\w\s]*(?="")|\w+|""[\w\s]*"""来自SO中的另一个帖子,它将字符串拆分为

research
library
"not available"
author
"Bernard Shaw"
Run Code Online (Sandbox Code Playgroud)

遗憾的是,这不符合我的确切要求.

我正在寻找任何正则表达式,这将成功.

任何帮助赞赏.

c# regex split

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

默认情况下,在Excel中打开电子表格xml

在Web应用程序中,我使用从Excel 2010创建的XSL模板生成电子表格XML.我希望此电子表格XML默认在Excel中打开.因此,我将以下属性添加到响应中

Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "Attachment;Filename=export.xls");
Response.Charset = "";
Run Code Online (Sandbox Code Playgroud)

这将在Excel中打开文件,但由于Excel 2010的扩展强化功能,显示提示 -

您尝试打开的文件'export [1] .xls'的格式与文件扩展名指定的格式不同.在打开文件之前,请验证文件是否已损坏且是否来自受信任的源.你想现在打开文件吗?

如果我点击是,它打开正常.但是,有没有办法可以完全跳过提示?我已阅读有关注册表更改以禁用用户计算机中的提示.但是,这是一个公共网站,该解决方案将无法运作.

我可以将附件文件名设置为export.xml.如果我保存并在Excel中打开,则没有提示.但默认情况下,XML不会在Excel中打开.

任何想法,在Excel中打开电子表格xml,没有提示?

xml excel spreadsheet

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

使用LINQ将常量字符串连接到List <string>中的每个项目

我正在使用C#和.Net 4.0.

我有List<string>一些值,比如x1,x2,x3.对于每个值List<string>,我需要连接一个常量值,比如"y"并返回List<string> x1y,x2y和x3y.

是否有Linq方法可以做到这一点?

c# linq string-concatenation

9
推荐指数
3
解决办法
8664
查看次数

在Asp.net中运行外部可执行文件的内存限制

我在.NET 4.0中运行的C#Web应用程序中使用WkhtmltoPdf从HTML文件生成PDF.通常一切正常,除非HTML文件的大小低于250KB.一旦HTML文件大小超过该值,运行wkhtmltopdf.exe的进程就会产生如下异常.在任务管理器上,我已经看到wkhtmltopdf.exe进程的内存值没有超过40,096 K的值,我相信这就是为什么在这两者之间放弃进程的原因.

我们如何配置外部exes的内存限制可以增加?有没有其他方法可以解决这个问题?

更多信息:
当我直接从命令行运行转换时,PDF生成正常.所以,它不太可能成为WkhtmlToPdf的问题.

错误来自localhost.我在DEV服务器上尝试过相同的结果.

编辑:

更具体的异常消息: - 对于Process对象的MainModule属性,错误显示 - {"只有ReadProcessMemory或WriteProcessMemory请求的一部分已完成"},具有NativeErrorCode值 - 299.

例外:

> [Exception: Loading pages (1/6) [>                                    
> ] 0% [======>                                                     ]
> 10% [======>                                                     ] 11%
> [=======>                                                    ] 13%
> [=========>                                                  ] 15%
> [==========>                                                 ] 18%
> [============>                                               ] 20%
> [=============>                                              ] 22%
> [==============>                                             ] 24%
> [===============>                                            ] 26%
> [=================>                                          ] 29%
> [==================>                                         ] 31%
> [===================>                                        ] 33%
> [=====================>                                      ] 35%
> [======================>                                     ] 37% …
Run Code Online (Sandbox Code Playgroud)

asp.net memory-management external-process wkhtmltopdf

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

通过代理服务器路由Google Analytics v3 API

我们正在使用Google Analytics API v3 (点网版)在我们的网站上报告一些统计数据.我的代码在我的本地计算机上正常运行,但由于某些防火墙规则,它无法在生产服务器上运行.我们的系统管理员建议尝试使用代理.我在互联网上搜索了为Google AnalyticsAPI服务设置代理的任何指南,但没有运气.感谢这方面的任何指示.

编辑:

   public DataTable GetSearchTrends()
    {
        string GoogleAnalyticsProfileId = AppConfigManager.GetGoogleAnalyticsProfileIdForInis();

        var service = new AnalyticsService(new BaseClientService.Initializer()
        {
            Authenticator = Authenticate()

        });

            DataResource.GaResource.GetRequest request = service.Data.Ga.Get(
            GoogleAnalyticsProfileId,
            string.Format("{0:yyyy-MM-dd}", StartDate),
            string.Format("{0:yyyy-MM-dd}", EndDate),
            GoogleAnalyticsSearchUniquesMetric
            );

        request.Dimensions = GoogleAnalyticsSearchKeywordMetric;
        request.Sort = string.Concat("-", GoogleAnalyticsSearchUniquesMetric);
        request.MaxResults = NumberOfSearchTrendsToFetch;

        GaData response = request.Fetch();

        return SearchTrendsHelper.ConvertToDataTable(
            response.Rows,
            SearchTrendsKeywordsExcludeList,
            NumberOfSearchTrendsToDisplay
            );
    }


   private IAuthenticator Authenticate()
    {
        string GoogleAnalyticsServiceScope = AnalyticsService.Scopes.AnalyticsReadonly.GetStringValue();
        string GoogleApiServiceAccountId = AppConfigManager.GetGoogleApiServiceAccountId();
        string GoogleApiServiceAccountKeyFile = AppConfigManager.GetGoogleApiServiceAccountKeyFile();
        string GoogleApiServiceAccountKeyPassword = AppConfigManager.GetGoogleApiServiceAccountKeyPassword();
        AuthorizationServerDescription …
Run Code Online (Sandbox Code Playgroud)

.net google-api google-analytics-api google-api-dotnet-client

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

将 XML 中的 HTML 实体转换为 C# 中的等效 Unicode

我在 Web 服务作为类型返回的 XML 中有几个 HTML 实体XmlDocument。在应用 XSLT 转换之前,我需要将它们替换为等效的 Unicode 字符。

XML 片段

<ics>
 <record>
  <metadata>
    <meta name="Abstract" content="In the series of compounds observed after effect of &amp;#947;-quanta"/>
  </metadata>
 </record>
</ics>
Run Code Online (Sandbox Code Playgroud)

我正在使用 C# 和 .Net 4.0。我尝试使用上述 XmlDocument 的HttpUtility.HtmlDecode属性OuterXml,但它不会将 HTML 实体转换为 Unicode。

如何才能实现这一目标?

编辑:

我看到应用 HtmlDecode 一旦&amp;#947;到达&#947;. 如果我再次应用它,我会得到所需的 Unicode。

还有更好的方法吗?

c# xml html-entities

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

如何使用Resharper查找未注释的公共方法

我在Visual Studio 2010中使用Resharper 7.1.有没有办法在整个解决方案中找到所有未注释的(没有方法摘要和参数描述)公共方法?

resharper visual-studio-2010 c#-4.0 resharper-7.1

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

XSLT - 检查元素字符串中是否存在模式

我有以下元素作为更大的XML的一部分

<MT N="NonEnglishAbstract" V="[DE] Deutsch Abstract text [FR] French Abstract text"/>
Run Code Online (Sandbox Code Playgroud)

我需要对@V属性中的值进行一些格式化,只要它包含[DE],[FR]或任何两个大写字母代表方括号内的国家代码.

如果不存在这样的模式,我只需要编写@V没有任何格式的值.

我可以使用XSLT 2.0解决方案

我希望我可以使用matches()函数

<xsl:choose>
<xsl:when test="matches(@V,'\[([A-Z]{{2}})\]([^\[]+'">
//Do something
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@V"/>
</xsl:otherwise>
</xsl:choose>
Run Code Online (Sandbox Code Playgroud)

regex xslt xslt-2.0

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

对于带有命名空间的XML,XPATH返回null

我有以下XML.

<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://localhost/gsainis/GsaInisWebService">
    <string>
        <gsafeed>
            <group action="add">
                <record>
                 ......
                 ......
                </record>
            </group>
        </gsafeed>
   </string>
</ArrayOfString>
Run Code Online (Sandbox Code Playgroud)

我正在使用C#代码(.NET 4.0)来解析此XML.我使用下面的代码选择<record>上面的XML中的所有节点.

XmlNamespaceManager xmlnsmgr = new XmlNamespaceManager(INISRecordXMLdoc.NameTable);
xmlnsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
xmlnsmgr.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
xmlnsmgr.AddNamespace(string.Empty, "http://localhost/gsainis/GsaInisWebService");

foreach (XmlNode node in INISRecordXMLdoc.SelectNodes("//ArrayOfString/string/gsafeed/group/record",xmlnsmgr))
{
    //Do something
}
Run Code Online (Sandbox Code Playgroud)

问题是foreach循环从未执行过.应该使用什么正确的XPath,以便获得所有<record>节点?

c# xml asp.net xpath

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

wkhtmltopdf - 非英文字体未显示在导出的 PDF 中

我正在使用 wkhtmltopdf.exe 将 HTML 转换为 PDF,使用以下源代码。问题是 - PDF 显示“?” 代替所有非英文字符,如中文、日文、俄文、阿拉伯文。输出为 HTML 时,字符显示正确。我尝试为 HTML(utf-8、utf-16、gb2312)设置不同的编码,但 PDF 不呈现非英语语言。

我在 wkhtmltopdf 论坛上阅读了有关在服务器上安装中文字体的信息,但看起来它们不适用于 Windows 服务器环境。此外,字体似乎在服务器上可用,因为 HTML 呈现正确?

有什么想法可以让它发挥作用吗?

代码:

private void WritePDF(string html)
    {
        string inFileName,
                outFileName,
                tempPath;
        Process p;
        System.IO.StreamWriter stdin;
        ProcessStartInfo psi = new ProcessStartInfo();


        tempPath = Request.PhysicalApplicationPath 
            + ConfigurationManager.AppSettings[Constants.AppSettings.ExportToPdfTempFolder];
        inFileName = Session.SessionID + ".htm";
        outFileName = Session.SessionID + ".pdf";

        // run the conversion utility
        psi.UseShellExecute = false;
        psi.FileName = Server.MapPath(ConfigurationManager.AppSettings[Constants.AppSettings.ExportToPdfExecutablePath]);
        psi.CreateNoWindow = true;
        psi.RedirectStandardInput = true;
        psi.RedirectStandardOutput = true;
        psi.RedirectStandardError = true; …
Run Code Online (Sandbox Code Playgroud)

c# html-to-pdf wkhtmltopdf

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

将MooTools js脚本转换为jquery

我一直在努力做到这一点!任何人都可以帮我将这部分MooTools js脚本转换成jquery吗?该脚本是动态查询构造函数.实时实施在http://opl.bibliocommons.com/search中.

我需要转换的脚本如下.我可以理解这个脚本正在做什么,但我不知道可以执行相同工作的等效jquery函数.任何有关如何处理此事的指示表示赞赏.

var AdvancedSearch = new Class({
    Implements: [Options],
    options: {
        disable_form_message: "Editing this field means you won't be able to use the constructor form. Continue?"
    },
    initialize: function (instance, options) {
        this.setOptions(options);
        this.instance = $(instance);
        this.query_chunks = this.instance.getElements('div.query_chunk');
        this.not_chunks = this.instance.getElements('div.not_chunk');

        this.instance.addEvent('submit', this.do_search.bindWithEvent(this));

        this.term_count = this.query_chunks.length;
        this.not_term_count = this.not_chunks.length;

        this.query_field = $('custom_query');
        if ($('custom_edit').value == 'false') {
            this.query_field.removeEvents('focus');
            this.query_field.addEvent('focus', this.disable_form_elements.bindWithEvent(this));
        }

        this.operation = $('operator');
        if (this.operation) {
            this.operation.addEvent('change', this.construct_query.bindWithEvent(this));
        }


        this.query_chunks.each(function (el, i) {
            el.getElement('select.parameter').addEvent('change', this.construct_query.bindWithEvent(this)); …
Run Code Online (Sandbox Code Playgroud)

jquery mootools

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