indexof

LINQ indexOf a particular entry

夙愿已清 提交于 2019-12-18 14:13:05
问题 I have an MVC3 C#.Net web app. I have the below string array. public static string[] HeaderNamesWbs = new[] { WBS_NUMBER, BOE_TITLE, SOW_DESCRIPTION, HARRIS_WIN_THEME, COST_BOGEY }; I want to find the Index of a given entry when in another loop. I thought the list would have an IndexOf. I can't find it. Any ideas? 回答1: Well you can use Array.IndexOf : int index = Array.IndexOf(HeaderNamesWbs, someValue); Or just declare HeaderNamesWbs as an IList<string> instead - which can still be an array

Getting Index of an item in an arraylist;

白昼怎懂夜的黑 提交于 2019-12-18 14:12:12
问题 I have a Class called AuctionItem . The AuctionItem Class has a method called getName() that returns a String . If I have an ArrayList of type AuctionItem , what is the best way to return the index of an item in the ArrayList that has a specific name? I know that there is an .indexOf() function. The parameter for this function is an object. To find the item that has a name, should I just use a for loop, and when the item is found, return the element position in the ArrayList ? Is there a

Get index of object in a list using Linq [duplicate]

人盡茶涼 提交于 2019-12-17 23:09:56
问题 This question already has answers here : How to get index using LINQ? [duplicate] (7 answers) Closed 5 years ago . I am new to Linq. I have a Customers table.ID,FullName,Organization,Location being the columns. I have a query in Sqlite returning me 2500 records of customers. I have to find the index of the customer where ID=150 for example from this result set. Its a List of Customers. The result set of the query is ordered by organization. I tried with FindIndex and IndexOf but getting

Getting a collection of index values using a LINQ query

纵然是瞬间 提交于 2019-12-17 18:54:37
问题 Is there a better way to do this? string[] s = {"zero", "one", "two", "three", "four", "five"}; var x = s .Select((a,i) => new {Value = a, Index = i}) .Where(b => b.Value.StartsWith("t")) .Select(c => c.Index); i.e. I'm looking for a more efficient or more elegant way to get the positions of the items matching the criteria. 回答1: You could easily add your own extension method: public static IEnumerable<int> IndexesWhere<T>(this IEnumerable<T> source, Func<T, bool> predicate) { int index=0;

Finding position of an element in a two-dimensional array?

我怕爱的太早我们不能终老 提交于 2019-12-17 16:58:09
问题 Well simple question here (maybe not a simple answer?) Say I have a two dimensional array [0] [1] [2] [3] [4] [5] [6] [7] [8] Now suppose I want to get the position of the number 6 I know with a one-dimensional array i can use Array.indexOf() but what would my options be with 2-dimensional arrays? Thanks! 回答1: I'd say something like this: public static Tuple<int, int> CoordinatesOf<T>(this T[,] matrix, T value) { int w = matrix.GetLength(0); // width int h = matrix.GetLength(1); // height for

window.location.indexOf not working in Javascript

折月煮酒 提交于 2019-12-17 14:01:36
问题 Below is what I have. var myString = "http://localhost:8888/www.smart-kw.com/"; alert(myString.indexOf("localhost")); This give me alert... however if I change var myString = "http://localhost:8888/www.smart-kw.com/"; to var myString = window.location; , it won't work (I don't get alert). var myString = window.location; alert(myString.indexOf("localhost")); 回答1: window.location is an accessor property, and getting its value gives you an object, not a string, and so it doesn't have an indexOf

Index of element in NumPy array

岁酱吖の 提交于 2019-12-17 10:21:39
问题 In Python we can get the index of a value in an array by using .index(). How can I do it with a NumPy array? When I try to do decoding.index(i) it says that the NumPy library doesn't support this function. Is there a way to do it? 回答1: Use np.where to get the indices where a given condition is True . Examples: For a 2D np.ndarray called a : i, j = np.where(a == value) # when comparing arrays of integers i, j = np.where(np.isclose(a, value)) # when comparing floating-point arrays For a 1D

How to trim a file extension from a String in JavaScript?

两盒软妹~` 提交于 2019-12-17 08:02:12
问题 For example, assuming that x = filename.jpg , I want to get filename , where filename could be any file name (Let's assume the file name only contains [a-zA-Z0-9-_] to simplify.). I saw x.substring(0, x.indexOf('.jpg')) on DZone Snippets, but wouldn't x.substring(0, x.length-4) perform better? Because, length is a property and doesn't do character checking whereas indexOf() is a function and does character checking. 回答1: If you know the length of the extension, you can use x.slice(0, -4)

how to return the character which is at the index?

拟墨画扇 提交于 2019-12-17 07:51:39
问题 I know that i could return the index of a particular character of a string with indexof() function. But how i could return the character with the particular index? 回答1: string s = "hello"; char c = s[1]; // now c == 'e' See also Substring , to return more than one character. 回答2: Do you mean like this int index = 2; string s = "hello"; Console.WriteLine(s[index]); string also implements IEnumberable<char> so you can also enumerate it like this foreach (char c in s) Console.WriteLine(c); 来源:

How do I check if a char is a vowel?

故事扮演 提交于 2019-12-17 07:47:11
问题 This Java code is giving me trouble: String word = <Uses an input> int y = 3; char z; do { z = word.charAt(y); if (z!='a' || z!='e' || z!='i' || z!='o' || z!='u')) { for (int i = 0; i==y; i++) { wordT = wordT + word.charAt(i); } break; } } while(true); I want to check if the third letter of word is a non-vowel, and if it is I want it to return the non-vowel and any characters preceding it. If it is a vowel, it checks the next letter in the string, if it's also a vowel then it checks the next