自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

查詢(xún)LINQ字符串方法淺析

開(kāi)發(fā) 后端
本文介紹了一種查詢(xún)LINQ字符串的方法,LINQ 可用于查詢(xún)和轉(zhuǎn)換LINQ字符串和字符串集合。之后可以使用 LINQ 來(lái)查詢(xún)或修改由正則表達(dá)式返回的 MatchCollection 結(jié)果。

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

LINQ可用于查詢(xún)和轉(zhuǎn)換LINQ字符串和字符串集合。它對(duì)文本文件中的半結(jié)構(gòu)化數(shù)據(jù)尤其有用。LINQ 查詢(xún)可與傳統(tǒng)的字符串函數(shù)和正則表達(dá)式結(jié)合使用。例如,可以使用 Split 或 Split 方法來(lái)創(chuàng)建字符串?dāng)?shù)組,然后可以使用LINQ 來(lái)查詢(xún)或修改此數(shù)組??梢栽?LINQ 查詢(xún)的where 子句中使用IsMatch 方法??梢允褂肔INQ 來(lái)查詢(xún)或修改由正則表達(dá)式返回的MatchCollection 結(jié)果。

LINQ查詢(xún)匹配給定的字符

  1. using System;  
  2. using System.Linq;  
  3. using System.Collections.Generic;  
  4. using System.Collections;  
  5.  
  6.  
  7. /// <summary>  
  8. ///Class1 學(xué)習(xí)linq   
  9.  
  10. /// </summary>  
  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ù)組里查詢(xún)符合條件的數(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.         //返回查詢(xún)后的結(jié)果  
  46.         return str+":::"+wordCount;  
  47.  
  48.     }  
  49.       

【編輯推薦】

  1. LINQ——語(yǔ)言級(jí)集成查詢(xún)?nèi)腴T(mén)指南
  2. LINQ的演變及其對(duì)C#設(shè)計(jì)的影響
  3. LINQ查詢(xún)的目的與實(shí)現(xiàn)手段
  4. LINQ查詢(xún)表達(dá)式深入剖析
  5. 實(shí)例二:綁定到LINQ查詢(xún)的結(jié)果
責(zé)任編輯:林琳 來(lái)源: 博客園
相關(guān)推薦

2009-09-14 10:42:03

LINQ生成字符串

2009-07-16 17:01:09

Swing字符串

2009-09-17 11:16:44

LINQ代碼生成

2009-09-10 14:47:53

Linq .NET查詢(xún)

2009-09-14 18:23:59

LINQ嵌套查詢(xún)

2009-09-17 18:05:15

linq to sql

2009-09-15 09:19:22

linq動(dòng)態(tài)條件

2009-09-18 15:22:14

DataContextLINQ to SQL

2009-09-15 17:16:58

LINQ查詢(xún)操作符

2009-09-15 10:35:11

linq多表查詢(xún)

2009-09-14 17:10:57

LINQ模糊查詢(xún)

2009-09-14 19:14:51

LINQ動(dòng)態(tài)查詢(xún)

2009-09-08 16:36:10

LINQ查詢(xún)基于泛型類(lèi)

2009-09-16 17:29:10

Linq查詢(xún)二維數(shù)組

2009-09-17 08:47:00

Linq插入數(shù)據(jù)

2009-08-11 10:26:49

C#算法C#字符串反轉(zhuǎn)

2009-09-15 14:30:11

Linq連接

2009-09-14 18:19:49

LINQ模糊查詢(xún)

2009-09-17 09:09:50

Lambda表達(dá)式Linq查詢(xún)

2009-12-11 13:16:04

PHP查詢(xún)字符串
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)