How to query for characters in a string (LINQ) (C# ...
docs.microsoft.com › en-us › dotnetSep 15, 2021 · int count = stringQuery.Count(); Console.WriteLine("Count = {0}", count); // Select all characters before the first '-' IEnumerable<char> stringQuery2 = aString.TakeWhile(c => c != '-'); // Execute the second query foreach (char c in stringQuery2) Console.Write(c); Console.WriteLine(System.Environment.NewLine + "Press any key to exit"); Console.ReadKey(); } } /* Output: Output: 9 9 7 4 1 2 8 9 Count = 8 ABCDE99F */
Find a character in a String using C#
www.dotnetheaven.com › article › find-a-character-inJun 13, 2019 · In this article we will discuss about how to find a character in a string in C#. 9351. The IndexOf and LastIndexOf methods can be used to find an index of a character within a string. The IndexOf method returns the 0 based index of the first occurrence of a character. If a character is found, it returns the index of the character; otherwise returns -1;