indexof

How to find indexOf element in jQuery array?

懵懂的女人 提交于 2019-12-10 09:43:52
问题 I have two selectors var allNodes = $("a.historyEntry"); var errorNodes = $("a.historyEntry.error"); I would like to to find a node before first error node, so I need to find an index of first error node, how to do it? I tried to use inArray method, but it doesn't work for this $.inArray(allNodes, errorNodes.first()) or $.inArray(allNodes, $(errorNodes.first())) Is there any fast way to do it in jQuery or do I have to use for loop? 回答1: index()? It's like indexOf ... but just without the Of .

Swift: cannot convert value of type to @noescape while call indexOf, after filter using filter function

佐手、 提交于 2019-12-10 01:14:14
问题 In Swift 2, I'm receiving an error: Cannot convert value of type '[String:AnyObject]' to expected argument type '@noescape ([String:AnyObject])' throws -> Bool" //today = NSDate() //array : [[String:AnyObject]] // I use if let because of we might now get element in the array matching our condition if let elementOfArray = array.filter({$0["id"] as? Int == anotherDictionary["matchID"] as? Int && ($0["nextFireDate"] as? NSDate)?.compare(today) == NSComparisonResult.OrderedAscending}).first { let

Need to reset just the indexes of a Javascript array

纵然是瞬间 提交于 2019-12-09 17:21:22
问题 I have a for loop which returns an array. Return: 1st loop: arr[0] arr[1] arr[2] arr[3] Here the length I get is 4 (Not a problem). Return: 2nd loop arr[4] arr[5] arr[6] arr[7] arr[8] Here the length I get is 9 . What I want here is the actual count of the indexes i.e I need it to be 5 . How can I do this. And is there a way that when I enter each loop every time it starts from 0 so that I get proper length in all the loops? 回答1: This is easily done natively using Array.filter: resetArr =

c# substring indexof

你离开我真会死。 提交于 2019-12-09 17:04:54
问题 i have a string which looks like this - "FirstName||Sam LastName||Jones Address||123 Main ST ..." (100 more different values) I want to find only Sam and Jones from the entire string. so string firstname = originalstring.substring ... etc. Does anyone know how I can do this? ADDITION - I think i forgot to mention couple of things. FirstName||Sam\r\n MiddleName||\r\n LastName||Jones\r\n .... So now if i count the number of characters that wont help me, cause could need more items other than

Why is this List<>.IndexOf code so much faster than the List[i] and manual compare?

给你一囗甜甜゛ 提交于 2019-12-09 10:57:04
问题 I'm running AQTime on this piece of code, I found that .IndexOf takes 16% of the time vs close to 80% for the other piece... They appear to use the same IsEqual and other routines. Called 116,000 times inserting 30,000 items. None of the List<> objects gets over 200 elements. (I may be using AQTime incorrectly, I'm looking into this) class PointD : IEquatable<PointD> { public double X, Y, Z; bool IEquatable<PointD>.Equals(PointD other) { return ((X == other.X) && (Y == other.Y) && (Z == other

IndexOf method returns 0 when it should had return -1 in C# / Java

大憨熊 提交于 2019-12-09 03:10:56
问题 A friend of mine came to me with this strange behavior which i can't explain, any insight view would be appreciated. Im running VS 2005 (C# 2.0), the following code show the behavior int rr = "test".IndexOf(""); Console.WriteLine(rr.ToString()); the above code, print "0" which clearly show it should have return -1 This also happen in Java where the following Class show the behavior: public class Test{ public static void main(String[] args){ System.out.println("Result->"+("test".indexOf("")));

JavaScript indexOf() - how to get specific index

丶灬走出姿态 提交于 2019-12-08 16:39:20
问题 Let's say I have a URL: http://something.com/somethingheretoo and I want to get what's after the 3rd instance of / ? something like the equivalent of indexOf() which lets me input which instance of the backslash I want. 回答1: If you know it starts with http:// or https:// , just skip past that part with this one-liner : var content = aURL.substring(aURL.indexOf('/', 8)); This gives you more flexibility if there are multiple slashes in that segment you want. 回答2: s = 'http://something.com

Strange results from IndexOf on German string

我只是一个虾纸丫 提交于 2019-12-08 16:04:45
问题 I have string "Ärger,-Ökonom-i-Übermut-ẞ-ß" and when I run IndexOf("--") I get a result of 23. If I use Replace on same string nothing gets replaced. I don't understand what is happening, so can someone please shed some light on this issue? Application Culture is set on Croatian, it's not German, and framework version is 3.5. Changing culture to German (de-DE) doesn't change this strange behavior. Here is the screenshot from the debugger: 回答1: Since Mr Lister doesn't want his well deserved

Array indexOf implementation for Internet Explorer

随声附和 提交于 2019-12-07 15:22:44
问题 There are plenty of solutions on how to get the indexOf implementation into the Array prototype so that it works under Internet Explorer, however I've stumbled upon an issue that doesn't seem to be addressed anywhere I've looked so far. Using the pretty well agreed upon implementation at MDC, I have the following code that's being problematic now: // indexOf support for IE (from MDC) if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(elt /*, from*/) { var len = this.length >>>

How to return the next indexOf after a previous?

蓝咒 提交于 2019-12-07 14:10:25
问题 For example: str = "(a+b)*(c+d)*(e+f)" str.indexOf("(") = 0 str.lastIndexOf("(") = 12 How to get the index in second bracket? (c+d) <- this 回答1: Try this : String word = "(a+b)*(c+d)*(e+f)"; String c = "("; for (int index = word.indexOf(c);index >= 0; index = word.indexOf(c, index + 1)) { System.out.println(index);//////here you will get all the index of "(" } 回答2: int first = str.indexOf("("); int next = str.indexOf("(", first+1); have a look at API Documentation 回答3: You can use StringUtils