本文整理汇总了C#中System.String.Where方法的典型用法代码示例。如果您正苦于以下问题:C# String.Where方法的具体用法?C# String.Where怎么用?C# String.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String
的用法示例。
在下文中一共展示了String.Where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(String[] args)
{
String toolName = typeof(Program).GetTypeInfo().Assembly.GetName().Name;
String path = Path.GetFullPath(Directory.GetCurrentDirectory());
GennyApplication application = new GennyApplication();
Project project = ProjectReader.GetProject(path);
application.Name = project.Name;
application.BasePath = path;
if (args.Contains("--no-dispatch"))
{
new GennyCommand(application).Execute(args.Where(arg => arg != "--no-dispatch").ToArray());
}
else
{
ProjectDependenciesCommandFactory factory = new ProjectDependenciesCommandFactory(
project.GetTargetFrameworks().FirstOrDefault().FrameworkName,
Constants.DefaultConfiguration,
null,
null,
path);
factory
.Create(toolName, args.Concat(new[] { "--no-dispatch" }).ToArray())
.ForwardStdErr()
.ForwardStdOut()
.Execute();
}
}
示例2: ParseLog
static ParsedLog[] ParseLog(String[] lines)
{
return lines
.Where(x => x.Trim().Length > 0 && !x.StartsWith("#"))
.Select(x => new ParsedLog(x))
.ToArray();
}
示例3: AnalyzeWord
public static IEnumerable<CharacterCount> AnalyzeWord(String word)
{
return word.Where(c => !Char.IsWhiteSpace(c))
.OrderBy(Char.ToLower)
.GroupBy(c => c)
.Select(grouping => new CharacterCount { Key = grouping.Key, Count = grouping.Count() });
}
示例4: RemovePunctuation
public static String RemovePunctuation(String input)
{
String result = "";
String noPunc = new string(input.Where(c => !char.IsPunctuation(c)).ToArray());
result = noPunc;
return result;
}
示例5: ToDecimal
/// <summary>
/// Convert string value to decimal ignore the culture.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>Decimal value.</returns>
public static decimal ToDecimal(string value)
{
decimal number;
value = new String(value.Where(c => char.IsPunctuation(c) || char.IsNumber(c)).ToArray());
string tempValue = value;
var punctuation = value.Where(x => char.IsPunctuation(x)).Distinct();
int count = punctuation.Count();
NumberFormatInfo format = CultureInfo.InvariantCulture.NumberFormat;
switch (count)
{
case 0:
break;
case 1:
tempValue = value.Replace(",", ".");
break;
case 2:
if (punctuation.ElementAt(0) == '.')
tempValue = SwapChar(value, '.', ',');
break;
default:
throw new InvalidCastException();
}
number = decimal.Parse(tempValue, format);
return number;
}
示例6: IsNameMatch
public static Boolean IsNameMatch(this MangaObject value, String name)
{
if (value == null)
return false;
String _name = new String(name.Where(Char.IsLetterOrDigit).ToArray()).ToLower();
return new String(value.Name.Where(Char.IsLetterOrDigit).ToArray()).ToLower().Contains(_name) ||
value.AlternateNames.FirstOrDefault(o => new String(o.Where(Char.IsLetterOrDigit).ToArray()).ToLower().Contains(_name)) != null;
}
示例7: StartWatch
public void StartWatch(String[] watchPaths)
{
foreach (var watchPath in watchPaths.Where(x => Directory.Exists(x) || File.Exists(x)))
{
if (!String.IsNullOrWhiteSpace(watchPath))
{
StartWatch(watchPath);
}
}
}
示例8: Hashids
public Hashids(string salt = "", int minHashLength = MIN_HASH_LENGTH, string alphabet = DEFAULT_ALPHABET) {
if (string.IsNullOrWhiteSpace(alphabet))
throw new ArgumentNullException("alphabet");
if (alphabet.Contains(' '))
throw new ArgumentException("alphabet cannot contain spaces", "alphabet");
Alphabet = new String(alphabet.Distinct().ToArray());
Salt = salt;
MinHashLength = minHashLength;
// separators should be in the alphabet
Separators = DEFAULT_SEPARATORS;
Separators = new String(Separators.Where(x => Alphabet.Contains(x)).ToArray());
if (string.IsNullOrWhiteSpace(Separators))
throw new ArgumentException("alphabet does not contain separators", "separators");
Separators = ConsistentShuffle(input: Separators, salt: Salt);
// remove separator characters from the alphabet
Alphabet = new String(Alphabet.Where(x => !Separators.Contains(x)).ToArray());
if (string.IsNullOrWhiteSpace(Alphabet) || Alphabet.Length < MIN_ALPHABET_LENGTH)
throw new ArgumentException("alphabet must contain atleast " + MIN_ALPHABET_LENGTH + " unique, non-separator characters.", "alphabet");
double sepDivisor = 3.5;
if ((Separators.Length == 0) || (((double)Alphabet.Length / (double)Separators.Length) > sepDivisor)) {
int sepsLength = (int)Math.Ceiling(Alphabet.Length / sepDivisor);
if (sepsLength == 1)
sepsLength++;
if (sepsLength > Separators.Length) {
int diff = sepsLength - Separators.Length;
Separators += Alphabet.Substring(0, diff);
Alphabet = Alphabet.Substring(diff);
} else {
Separators = Separators.Substring(0, sepsLength);
}
}
double guardDivisor = 12.0;
Alphabet = ConsistentShuffle(input: Alphabet, salt: Salt);
int guardCount = (int)Math.Ceiling(Alphabet.Length / guardDivisor);
if (Alphabet.Length < 3) {
Guards = Separators.Substring(0, guardCount);
Separators = Separators.Substring(guardCount);
} else {
Guards = Alphabet.Substring(0, guardCount);
Alphabet = Alphabet.Substring(guardCount);
}
}
示例9: DiceRoll
/// <summary>
/// Parse a string representation of a dice roll (a roll string)
/// </summary>
/// <param name="input">Roll string to parse</param>
public DiceRoll(String input)
{
if (input == null)
{
this.d10 = this.d5 = this.Modifier = 0;
return;
}
String roll = new string(input.Where(c => !Char.IsWhiteSpace(c)).ToArray());//strip whitespace
this.d10 = this.d5 = 0;
int index = 0;
int previous = index;
while (index < roll.Length)
{
if (roll[index++] == 'd')
{
if (roll[index] == '1' && roll[index + 1] == '0')
{
if (previous == index - 1)
d10 = 1;
else
d10 = Int32.Parse(roll.Substring(previous, index - previous - 1));
index++;//move to the 0 so the final ++ puts after the dice
}
else if (roll[index] == '5')
{
if (previous == index - 2)
d5 = 1;
else
d5 = Int32.Parse(roll.Substring(previous, index - previous - 1));
}
else
throw new FormatException("Only d10 and d5 are supported");
index++;//point after the dice
previous = index;//advance last found
}
}
if (previous == index)
Modifier = 0;
else
Modifier = Int32.Parse(roll.Substring(previous, index - previous));
}
示例10: getNews
public String[] getNews(String[] topics) {
topics = topics.Where(x => !string.IsNullOrEmpty(x)).ToArray();
String baseUrl = "https://webhose.io/search?token="your token";
String[] emptyArray=new String[1];
if(topics.Length==0){
emptyArray[1]="please give some input";
return emptyArray;
}
String query = "&q=";
for (int i = 0; i < topics.Length; i++)
{
if (i < topics.Length - 1)
{
query = query + topics[i] + " OR ";
}
else query = query + topics[i];
}
query = query + "&language=english" + "&size=100"+"&is_first=true";
HttpWebRequest request = WebRequest.Create(baseUrl+query) as HttpWebRequest;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(response.GetResponseStream());
XmlNodeList nl = xmlDoc.GetElementsByTagName("post");
String[] res = new String[nl.Count];
for (int i = 0; i < nl.Count; i++)
{
res[i] = nl.Item(i).ChildNodes.Item(2).InnerText;
}
return res;
}
示例11: CreateNewProperty
/// <summary>
/// Creates new unassigned property in database.
/// </summary>
/// <param name="name">Should be correct.</param>
/// <param name="systemName">Should be latin singleline word.</param>
/// <param name="type">Only types defined in this program.</param>
/// <param name="availableValues">Only for types with selection.</param>
/// <exception cref="ConnectionException" />
/// <exception cref="BadSystemNameException" />
/// <exception cref="BadPropertyTypeException" />
/// <exception cref="BadDisplayTypeNameException" />
public void CreateNewProperty(String name, String systemName, String type, String[] availableValues)
{
if(name == null)
{
throw new BadSystemNameException();
}
name = name.CutWhitespaces();
systemName = systemName.CutWhitespaces();
if(!TypeValidationHelper.IsValidSystemName(systemName))
{
throw new BadSystemNameException();
}
if(!TypeValidationHelper.IsValidType(type))
{
throw new BadPropertyTypeException();
}
if(!TypeValidationHelper.IsValidDisplayName(name))
{
throw new BadDisplayTypeNameException();
}
Property creating = new Property();
creating.DisplayName = name;
creating.SystemName = systemName;
creating.Type = type;
if (!ConnectionHelper.CreateProperty(creating))
{
throw new BadSystemNameException();
}
if (TypeValidationHelper.IsSelectable(type))
{
ConnectionHelper.AddAvailableValues(availableValues.Where(x => TypeValidationHelper.IsValidValue(x)), creating);
}
}
示例12: fixYearMonth
public static String fixYearMonth(String s, out int newPosition)
{
newPosition = -1;
String res = new String(s.Where(Char.IsDigit).ToArray());
if (res.Length > 4) {
res = res.Substring(0, 4);
//newPosition = 0;
}
if (res.Length == 3) {
int month = int.Parse(res.Substring(2, 1));
if (month > 1) {
res = res.Substring(0, 2);
newPosition = 2;
}
}
if (res.Length == 4) {
int month = int.Parse(res.Substring(2, 2));
if ((month <= 0) || (month > 12)) {
res = res.Substring(0, 2);
newPosition = 2;
}
}
return res;
}
示例13: ParseAsDirective
public static bool ParseAsDirective(SmaliLine rv, String sInst, ref String[] sWords, ref String sRawText)
{
switch (sInst)
{
case ".class":
rv.Instruction = LineInstruction.Class;
SetModifiers(rv, ref sWords, 1, sWords.Length - 1);
rv.aClassName = sWords[sWords.Length - 1];
break;
case ".super":
rv.Instruction = LineInstruction.Super;
rv.aType = sWords[1];
break;
case ".implements":
rv.Instruction = LineInstruction.Implements;
rv.aType = sWords[1];
break;
case ".source":
rv.Instruction = LineInstruction.Source;
rv.aExtra = sRawText;
break;
case ".field":
rv.Instruction = LineInstruction.Field;
SetModifiers(rv, ref sWords, 1, sWords.Length - 1);
sRawText = String.Join(" ", sWords.Where(x => !String.IsNullOrEmpty(x)).ToArray()).Trim();
rv.aName = sRawText.Split(':')[0];
rv.aType = sRawText.Split(':')[1];
break;
case ".method":
rv.Instruction = LineInstruction.Method;
SetModifiers(rv, ref sWords, 1, sWords.Length - 1);
sRawText = String.Join(" ", sWords.Where(x => !String.IsNullOrEmpty(x)).ToArray()).Trim();
rv.aExtra = sRawText;
break;
case ".prologue":
rv.Instruction = LineInstruction.Prologue;
break;
case ".registers":
rv.Instruction = LineInstruction.Registers;
break;
case ".line":
rv.Instruction = LineInstruction.Line;
break;
case ".end":
switch (sRawText)
{
case ".end method":
rv.Instruction = LineInstruction.EndMethod;
break;
}
break;
case ".param":
rv.Instruction = LineInstruction.Parameter;
sWords[1] = sWords[1].Replace(",", "");
rv.lRegisters[sWords[1].Trim()] = String.Empty;
rv.aName = sRawText.Substring(sRawText.IndexOf('"') + 1);
rv.aName = rv.aName.Substring(0, rv.aName.IndexOf('"'));
rv.aType = sRawText.Substring(sRawText.IndexOf('#') + 1).Trim();
break;
default:
return false;
}
return true;
}
示例14: Peek
/// <summary>
/// Peek ahead and see if the specified string is present.
/// </summary>
/// <param name="str">The string we are looking for.</param>
/// <returns>True if the string was found.</returns>
public bool Peek(String str)
{
return !str.Where((t, i) => Peek(i) != t).Any();
}
示例15: ProcessData
//.........这里部分代码省略.........
{
if (SplitValues[i].Contains("of")) { break; };
cncl1 = cncl1 + " " + SplitValues[i];//email body subject
cncl1 = cncl1.Replace("Description", "").Replace("\r\n", "");
}
IList<string> arrayAsList1 = (IList<string>)SplitValues;
int index1 = arrayAsList.IndexOf("being");
for (int i = index1 + 2; i < SplitValues.Length; i++)
{
if (SplitValues[i].Contains("on")) { break; };
cncl2 = cncl2 + " " + SplitValues[i];//email body subject
cncl2 = cncl2.Replace("Required", "").Replace("\r\n", "");
}
IList<string> arrayAsList2 = (IList<string>)SplitValues;
int index2 = arrayAsList.IndexOf("on");
cncl3 = SplitValues[index2 + 1].Replace("Product", "");
InsertCancelledOrders(cncl1, cncl2, cncl3, filename);
File.Move(file, System.Configuration.ConfigurationSettings.AppSettings["Cancelled"] + "\\" + filename);
File.Move(file.Replace("htm", "txt"), System.Configuration.ConfigurationSettings.AppSettings["Cancelled"] + "\\" + filename.Replace("htm", "txt"));
xmlDoc.RemoveAll();
continue;
}
string str11 = "", str22 = "", str33 = "";
try
{
#region Fixed on 9 Oct 2014
if (SplitValues[3] == "at")
{
var midleName = SplitValues[1];
SplitValues = SplitValues.Where(x => x != midleName).ToArray();
var lastName = SplitValues[1];
SplitValues[1] = midleName + " " + lastName;
}
#endregion
str11 = SplitValues[0] + " " + SplitValues[1];//primary contact
str22 = SplitValues[3] + " " + SplitValues[4] + " " + SplitValues[5];//company name
str22 = str22.Replace("Relating", "");
//if (SplitValues[7].Contains("to"))
//{
// str33 = "";
// for (int i = 8; i < SplitValues.Length; i++)
// {
// str33 = str33 + " " + SplitValues[i];//email body subject
// }
//}
//else
// str33 = SplitValues[7] + " " + SplitValues[8] + " " + SplitValues[9] + " " + SplitValues[10] + SplitValues[11];//email body subject
IList<string> arrayAsList = (IList<string>)SplitValues;
int index;
index = arrayAsList.IndexOf("Relating".Replace("\r\n", ""));
if (index == -1)
index = arrayAsList.IndexOf("\r\ncampaign:");//campaign:
if (index == -1)
index = arrayAsList.IndexOf("campaign:");//campaign:
for (int i = index + 1; i < SplitValues.Length; i++)
{
if (SplitValues[i].Contains("of")) { break; };