日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
查詢LINQ字符串方法淺析

LINQ字符串的查詢方式有很多,在這里介紹一種最常規(guī)的方法。如果大家有更多更好的方法,歡迎提出來一起討論。

LINQ可用于查詢和轉(zhuǎn)換LINQ字符串和字符串集合。它對文本文件中的半結(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查詢匹配給定的字符

 
 
 
  1. using System;  
  2. using System.Linq;  
  3. using System.Collections.Generic;  
  4. using System.Collections;  
  5.  
  6.  
  7. ///   
  8. ///Class1 學(xué)習(xí)linq   
  9.  
  10. ///   
  11. public class Class1  
  12. {  
  13.  public Class1()  
  14.  {  
  15.   //  
  16.   //TODO: 在此處添加構(gòu)造函數(shù)邏輯  
  17.   //  
  18.  }  
  19.     public string LinqToString()  
  20.     {  
  21.           string text = @"Historically, the world of data and the world of objects" +  
  22.           @" have not been well integrated. Programmers work in C# or Visual Basic" +  
  23.           @" and also in SQL or XQuery. On the one side are concepts such as classes," +  
  24.           @" objects, fields, inheritance, and .NET Framework APIs. On the other side" +  
  25.           @" are tables, columns, rows, nodes, and separate languages for dealing with" +  
  26.           @" them. Data types often require translation between the two worlds; there are" +  
  27.           @" different standard functions. Because the object world has no notion of query, a" +  
  28.           @" query can only be represented as a string without compile-time type checking or" +  
  29.           @" IntelliSense support in the IDE. Transferring data from SQL tables or XML trees to" +  
  30.           @" objects in memory is often tedious and error-prone.";  
  31.  
  32.         string searchTerm = "data";  
  33.  
  34.         //將內(nèi)容拆分成數(shù)組  
  35.         string[] source = text.Split(new char[] { '.', '?', '!', ' ', ';', ':', ',' }, StringSplitOptions.RemoveEmptyEntries);  
  36.  
  37.         //從數(shù)組里查詢符合條件的數(shù)據(jù)  
  38.         var matchQuery = from s in source where s.IndexOf('a')==0 orderby s ascending select s ;  
  39.  
  40.          
  41.         int wordCount = matchQuery.Count();  
  42.         string str="";  
  43.         foreach(string a in matchQuery)  
  44.             str+=a+",";  
  45.         //返回查詢后的結(jié)果  
  46.         return str+":::"+wordCount;  
  47.  
  48.     }  
  49.       

標(biāo)題名稱:查詢LINQ字符串方法淺析
文章網(wǎng)址:http://m.5511xx.com/article/coohdoi.html