除了这些值之外,从Everything中删除

时间:2014-04-22 22:27:05

标签: c# string parsing

我有这些值,我需要保留在我的字符串中

string[] units = new string[] {
                "zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
                "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
                "sixteen", "seventeen", "eighteen", "nineteen",
            };

string[] tens = new string[] { "", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };

string[] scales = new string[] { "hundred", "thousand", "million", "billion", "trillion" };
string[] seperators = new string[]{ "and" }

我需要删除除了这些值以外的所有其他内容 所以从这篇文章:

  

至少七十天

我想得到这个:

  

三十七

1 个答案:

答案 0 :(得分:3)

var strValue = "DUE IN THIRTY SEVEN DAYS".ToLower().Split(' ');

var numbers = (from u in units
               join s in strValue on u equals s
               select u);
Console.Write(string.Join(" ", numbers));

.Net Fiddle