Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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# 4.0 使用linq提取字符串_C# 4.0 - Fatal编程技术网

C# 4.0 使用linq提取字符串

C# 4.0 使用linq提取字符串,c#-4.0,C# 4.0,是否有一种使用linq提取字符串部分的好方法,例如: 我有 或 我的目标是提取字符串中没有最后一个“*”的任何内容 谢谢,我用的是C#你可能需要一个正则表达式(.*)\.*最简单的方法可能是使用 当然,除非您有特定的要求将LINQ用于学习目的。对于正则表达式: string input="System.Collections.Somethingelse.*"; string output=Regex.Matches(input,@"\b.*\b").Value; 输出为: "System.Co

是否有一种使用linq提取字符串部分的好方法,例如: 我有

我的目标是提取字符串中没有最后一个“*”的任何内容


谢谢,我用的是C#

你可能需要一个正则表达式<代码>(.*)\.*

最简单的方法可能是使用

当然,除非您有特定的要求将LINQ用于学习目的。

对于正则表达式:

string input="System.Collections.Somethingelse.*";
string output=Regex.Matches(input,@"\b.*\b").Value;
输出为:

"System.Collections.Somethingelse"
(因为“*”不是一个词)虽然简单

output=input.Replace(".*","");

本来可以用的:p

丹尼尔我试过你的正则表达式,但没什么变化。可能是我做错了。你应该在适当的地方添加额外的\到,或者如果在C#中,在字符串前面使用@。
string input="System.Collections.Somethingelse.*";
string output=Regex.Matches(input,@"\b.*\b").Value;
"System.Collections.Somethingelse"
output=input.Replace(".*","");