Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 字符串C上的linq#_C#_Linq_String - Fatal编程技术网

C# 字符串C上的linq#

C# 字符串C上的linq#,c#,linq,string,C#,Linq,String,有人能举例说明如何使用ling查询一长串文本并在该字符串中查找子字符串吗 static void Main(string[] args) { var found = "Where in the world is Carmen Sandiego".Split(' ').Where(part => part.StartsWith("i")); foreach (var part in found) Console.WriteLine(part); } 关于我不

有人能举例说明如何使用ling查询一长串文本并在该字符串中查找子字符串吗

static void Main(string[] args)
{
    var found = "Where in the world is Carmen Sandiego".Split(' ').Where(part => part.StartsWith("i"));
    foreach (var part in found)
        Console.WriteLine(part);
}

关于

我不会使用LINQ,我会使用,或a


你能发布一个你想搜索的字符串的示例和一个你想在该字符串中找到的子字符串的示例吗?

在这里做一个跳跃,但是如果你想在一个长字符串中找到一个单词,并使用LINQ根据一些标准将其挑选出来,你可以这样做

static void Main(string[] args)
{
    var found = "Where in the world is Carmen Sandiego".Split(' ').Where(part => part.StartsWith("i"));
    foreach (var part in found)
        Console.WriteLine(part);
}
private static string longString = "This is a really long string";
static void Main(string[] args)
{
    var query = from word in longString.Split(' ')
                where word.StartsWith("r")
                select word;
}

我没有说LINQ是否是一种合适的技术。

您能给出一个您想要搜索的字符串和子字符串的示例吗。String.Substring()不符合您的需要吗?您能给出一个示例字符串吗?最好使用正则表达式进行文本解析。有点重复: