草庐IT

get_shortcode_regex

全部标签

c# - 如何将 Regex.Matches 放入数组中?

我有多个正则表达式匹配项。如何将它们放入一个数组中并分别调用它们,例如ID[0]ID[1]?stringvalue=("{\"ID\":\"([A-Za-z0-9_.,]+)\",");stringID=Regex.Matches(textt,@value);` 最佳答案 你已经可以做到了,因为MatchCollection有一个intindexer这使您可以按索引访问匹配项。这是完全有效的:MatchCollectionmatches=Regex.Matches(textt,@value);MatchfirstMatch=matc

c# - 为什么我的文件没有被我的 Web API 函数的 GET 请求返回?

我有一个可通过我的RESTAPI访问的函数,它配置了ASP.NETWebAPI2.1,它应该向调用者返回一个图像。出于测试目的,我只是让它返回我现在存储在本地机器上的示例图像。方法如下:publicIHttpActionResultGetImage(){FileStreamfileStream=newFileStream("C:/img/hello.jpg",FileMode.Open);HttpContentcontent=newStreamContent(fileStream);content.Headers.ContentType=newSystem.Net.Http.Heade

C#如何Regex.Replace "\r\n"(实际字符,不是换行符)

我正在使用几个c#正则表达式清理一些可怕的文本。一个让我难过的问题是文本中有许多'\r\n'字符串,实际字符不是换行符。我试过:content=Regex.Replace(content,"\\r\\n","");和:content=Regex.Replace(content,"\r\n","");但它们都不起作用。最后我不得不使用:content=content.Replace("\\r\\n","\r\n");为了完成项目,但无法在正则表达式中完成它让我很烦。 最佳答案 \r和\n在Regex中也有特殊含义,因此需要对反斜杠进行

c# - 'GET OR SET ACCESSOR EXPECTED' 是什么意思?

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Data;usingSystem.Data.SqlClient;publicpartialclassRepeaterEx2:System.Web.UI.Page{SqlConnectioncn=null;SqlDataAdapterda=null;DataSetds=null;StringstrSqlQuery=

c# - 为什么这个通过 Regex 组循环打印输出两次?

我写了这个非常直接的正则表达式代码usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Text.RegularExpressions;usingSystem.Threading.Tasks;namespaceRegexTest1{classProgram{staticvoidMain(string[]args){stringa="\"foobar123==\"";Regexr=newRegex("^\"(.*)\"$");Matchm=r.Match(a);i

c# - 是否有使用 POST 而不是 GET 的 MVC Pager?

这是我的问题。我有一个具有大量搜索条件的SearchViewModel,这些值根本不适合URL。我目前正在使用TroyGoode的Html.PagedListPager,但它被设计为使用Url.Action()来发送URL中的参数。这是一个例子。我不认为客户端过滤是一种选择,因为我会有很多记录。@Html.PagedListPager((IPagedList)@Model.SearchResults,page=>Url.Action("Results",new{YearBuiltFrom=Model.YearBuiltFrom,}))}如果您只有一两个简单的参数,这是一个很好的解决方案

c# - .NET 框架中是否有针对不同 Web 方法类型(GET、PUT、POST、DELETE、HEAD)的常量?

我刚刚在创建RESTfulWCF服务时注意到WebInvoke属性上的Method参数区分大小写(需要大写)。所以,[WebInvoke(Method="Delete")]不等于[WebInvoke(Method="DELETE")]这个错误导致了ProtocolException:System.ServiceModel.ProtocolException:Theremoteserverreturnedanunexpectedresponse:(405)MethodNotAllowed.我想知道我应该使用.NET框架中的一组常量来代替上面示例中的“DELETE”。我当然可以定义我自己的

c# - 为什么要用blank get;放; C# 中的访问器?

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:c#:whyhaveemptygetsetpropertiesinsteadofusingapublicmembervariable?stringname;对比stringname{get;set;}假设您的get和set如上所述为空,指定它们有什么意义?

c# - 如何为数组数据成员定义 get 和 set?

我正在创建一个类Customer,它具有以下数据成员和属性:privatestringcustomerName;privatedouble[]totalPurchasesLastThreeDays;//arrayof3elementsthatwillholdthetotalsofhowmuchthecustomerpurchasedforthepastthreedaysi.e.element[0]=100,element[1]=50,element[2]=250publicstringCustomerName{get{returncustomerName;}set{customerNa

c# - System.StackOverflowException ,何时使用 get set 属性?

在wcfserviceLibrary.DLL中发生类型为“System.StackOverflowException”的未处理异常代码如下。[DataContract]publicclassmemberdesignations{[DataMember]publicstringDesigId{get{returnDesigId;}set{DesigId=value;}}[DataMember]publicstringDesignationName{get{returnDesignationName;}set{DesignationName=value;}}}然后我有如下的Typememb