這篇文章主要為大家展示了“LINQ如何查詢匹配給定的字符”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“LINQ如何查詢匹配給定的字符”這篇文章吧。
成都創新互聯公司是專業的揚州網站建設公司,揚州接單;提供網站建設、網站設計,網頁設計,網站設計,建網站,PHP網站建設等專業做網站服務;采用PHP框架,可快速的進行揚州網站開發網頁制作和功能擴展;專業做搜索引擎喜愛的網站,專業的做網站團隊,希望更多企業前來合作!
LINQ可用于查詢和轉換LINQ字符串和字符串集合。它對文本文件中的半結構化數據尤其有用。LINQ 查詢可與傳統的字符串函數和正則表達式結合使用。例如,可以使用 Split 或 Split 方法來創建字符串數組,然后可以使用LINQ 來查詢或修改此數組。可以在 LINQ 查詢的where 子句中使用IsMatch 方法。可以使用LINQ 來查詢或修改由正則表達式返回的MatchCollection 結果。
LINQ查詢匹配給定的字符
using System; using System.Linq; using System.Collections.Generic; using System.Collections; /// <summary> ///Class1 學習linq /// </summary> public class Class1 { public Class1() { // //TODO: 在此處添加構造函數邏輯 // } 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"; //將內容拆分成數組 string[] source = text.Split(new char[] { '.', '?', '!', ' ', ';', ':', ',' }, StringSplitOptions.RemoveEmptyEntries); //從數組里查詢符合條件的數據 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+","; //返回查詢后的結果 return str+":::"+wordCount; } }
以上是“LINQ如何查詢匹配給定的字符”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注創新互聯行業資訊頻道!
分享標題:LINQ如何查詢匹配給定的字符
網頁網址:http://m.2m8n56k.cn/article38/iesosp.html
成都網站建設公司_創新互聯,為您提供App開發、App設計、軟件開發、定制開發、全網營銷推廣、靜態網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:[email protected]。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯