這篇文章主要為大家展示了“LINQ如何查詢匹配給定的字符”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“LINQ如何查詢匹配給定的字符”這篇文章吧。
成都創(chuàng)新互聯(lián)公司是專業(yè)的揚(yáng)州網(wǎng)站建設(shè)公司,揚(yáng)州接單;提供網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì),網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行揚(yáng)州網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
LINQ可用于查詢和轉(zhuǎn)換LINQ字符串和字符串集合。它對(duì)文本文件中的半結(jié)構(gòu)化數(shù)據(jù)尤其有用。LINQ 查詢可與傳統(tǒng)的字符串函數(shù)和正則表達(dá)式結(jié)合使用。例如,可以使用 Split 或 Split 方法來創(chuàng)建字符串?dāng)?shù)組,然后可以使用LINQ 來查詢或修改此數(shù)組??梢栽?LINQ 查詢的where 子句中使用IsMatch 方法。可以使用LINQ 來查詢或修改由正則表達(dá)式返回的MatchCollection 結(jié)果。
LINQ查詢匹配給定的字符
using System; using System.Linq; using System.Collections.Generic; using System.Collections; /// <summary> ///Class1 學(xué)習(xí)linq /// </summary> public class Class1 { public Class1() { // //TODO: 在此處添加構(gòu)造函數(shù)邏輯 // } public string LinqToString() { string text = @"Historically, the world of data and the world of objects" + @" have not been well integrated. Programmers work in C# or Visual Basic" + @" and also in SQL or XQuery. On the one side are concepts such as classes," + @" objects, fields, inheritance, and .NET Framework APIs. On the other side" + @" are tables, columns, rows, nodes, and separate languages for dealing with" + @" them. Data types often require translation between the two worlds; there are" + @" different standard functions. Because the object world has no notion of query, a" + @" query can only be represented as a string without compile-time type checking or" + @" IntelliSense support in the IDE. Transferring data from SQL tables or XML trees to" + @" objects in memory is often tedious and error-prone."; string searchTerm = "data"; //將內(nèi)容拆分成數(shù)組 string[] source = text.Split(new char[] { '.', '?', '!', ' ', ';', ':', ',' }, StringSplitOptions.RemoveEmptyEntries); //從數(shù)組里查詢符合條件的數(shù)據(jù) var matchQuery = from s in source where s.IndexOf('a')==0 orderby s ascending select s ; int wordCount = matchQuery.Count(); string str=""; foreach(string a in matchQuery) str+=a+","; //返回查詢后的結(jié)果 return str+":::"+wordCount; } }
以上是“LINQ如何查詢匹配給定的字符”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
分享標(biāo)題:LINQ如何查詢匹配給定的字符
網(wǎng)頁網(wǎng)址:http://www.2m8n56k.cn/article38/iesosp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、App設(shè)計(jì)、軟件開發(fā)、定制開發(fā)、全網(wǎng)營銷推廣、靜態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)