There's no built-in method to do this, and no way to use a single call to IndexOf to achieve it either. If you need to find the one that occurs first, you'll need to make three separate calls to IndexOf, one for each of the values, and return the one...

You are getting the index of first occurrence of comma, then displaying it in the console. You need String.Substring method to get a substring from the user input.Substring method takes index as parameter and then returns the substring starting from that index until the end of your string unless you...

There are many ways to do this, but the easiest is to split the string into an array using a separator. If you know JavaScript, it's the equivalent of the .split() string method; Swift does have this functionality, but as you see there, it can get a little messy. You...

String#substring() is meant to throw an IndexOutOfBoundsException if the first parameter is greater than the second parameter. Effectively, a substring intends to take the lowest start index, and work its way up to but not including the highest index value you provide it. It has a range of [a, b)....

slice(start, end) is used to take a substring from the specified starting index to the ending index. So, text.slice(0, firstChar) will return a substring from start=0 to end=0 because the value of firstChar is 0.(this returns empty string) Now, the string the "Second World War" will be added to null...

Here's an other approach (might be a little overkill but it shows you an other way). The idea is to override the indexOf and lastIndexOf method so it would verify against your field "name": private static class TestObject { String id, name, version; public TestObject(String id, String name, String version)...

It gives a -1 because that's what indexOf returns when it can't find a match. (And it can't, since you're searching for a matching array vs a number) What you want is... noun1Num = Math.floor(Math.random() * 5); ...

The following code will find the index of the value you are looking for. This will return -1 if the value is not in the array. Taken from this SO post. I just added the alert at the end. var myArray = [0,1,2] could become var myArray = localValues; in...

IEEE-754 NaNs are not equal to themselves. The if statement is checking whether item is a NaN. If it is, the function needs to use special logic since the search loop testing for array[i] === item won't work. For further discussion, see Why is NaN not equal to NaN? and...

Besides the issue that DCoder identified — observables not taking parameters -, you had another bug here: score = parseFloat(student.scores()[i]); should have been score = parseFloat(student.scores()[i]()); The nth (or i-th) element of the observable array you access there is itself an observable, so before, you where passing a function to...

Look at the second argument to indexOf (specification link, MDN link). The second argument is the index at which to start looking. So use the value from one loop, plus one, as the starting point for the next search. Also, look for the string a, rather than using your variable...

According to the MDN docs: fromindex The index to start the search at. If the index is greater than or equal to the array's length, -1 is returned, which means the array will not be searched. If the provided index value is a negative number, it is taken as the...

You're misusing the the method indexOfObject:inSortedRange:. That method should only be used on pre-sorted arrays, the array you're checking is not sorted. Your array is not sorted, since "Camper" would come before all of the other objects in that array. The indexOfObject:inSortedRange: has undefined behavior when you give it an...

You can use the table rows and cells collections for the iteration. The following does a literal comparison of the text content, you may wish to process the text first to "normalise" it in regard to whitespace. <table id="t0"> <tr><td>foo<td>bar<td>fum</td> <tr><td>fum<td>bar<td>foo</td> <tr><td>foo<td>fum<td>fum</td> </table> <script> compareRows(document.getElementById('t0')); function compareRows(table) { var row,...

Change the following lines: int eq = relativeDN.indexOf('='); String sub = relativeDN.substring(0, eq); in your for loop to int eq = stringData[place].indexOf('='); String sub = stringData[place].substring(eq+1, stringData[place].length()); You need the separated strings in each iteration so you will need to use stringData[place]. As you were using relativeDN, it was taking...

Look at window.location.pathname and use str.slice to extract the bit you want, with str.indexOf to find the indices to start/end at var top_dir = window.location.pathname.slice( 1, window.location.pathname.indexOf('/', 1) ); ...

There are no objects in C, so there are no "methods" and you can't call IndexOf on a string literal. A string is nothing more than an array of characters in C. With that in mind, let's see how you can actually loop over the characters of a string: for...

Actual Problem A positive number when added to some other positive number, will always be smaller than the same number. So, i < (i + myName.length) will always be true, since i has a positive value 6, which is the index of first occurrence of John. So, your program runs...

Going from comments because an explanation of indexOf() would likely be too long for comments. Other answerers provide good alternatives, but I'll answer the way that is requested. I'm assuming you're working with a List of some kind (e.g. staff is an ArrayList<Employee>), as the Arrays utility class doesn't appear...

You can use the attribute equals selector $('.slicknav_item[href="javascript: void(0)"] span').remove(); Demo: Fiddle Your code $('.slicknav_item').attr('href') returns the href of first element with class slicknav_item so in your example the if condition won't get executed. Again your statement $('.slicknav_item span').remove(); will select all span elements which are descendants of .slicknav_item...

If by "row number", you mean the index of a Row object in the Rows collection, then you can't get that directly from the Row object. You can, as suggested in Vlad's comment, use something like this instead: for (var i = 0; i < table.Columns.Count; i++) { if (Enumerable.Range(0,...

It seems to me that the correct data structure to be using is an std::unordered_map<std::string,std::vector<std::string>>, and not an unordered_map<std::string,int>, as your current implementation is attempting. This, because the fields you want to store seem more like strings; some aren't ints at all. The first step is to extract the field...

If you are sure that your string will always be < HREF="yourpath" > , just apply the following: string yourInitialString = @"HREF="myimage.jpg""; string parsedString = yourInitialString.Replace(@"<HREF="").Replace(@"">"); If you need to parse HTML links href values, the best option will be using HtmlAgilityPack library. Solution with Html Agility Pack : HtmlWeb...

IMHO, you should just find all the matches the first time the user tries to find something, and then keep an index indicating which match is to be selected/highlighted. For example: private List<int> _matches; private string _textToFind; private bool _matchCase; private int _matchIndex; private void MoveToNextMatch(string textToFind, bool matchCase, bool...

There is no built in method that does this. Use the overloaded String#indexOf(String, int) method that accepts a starting position. Keep looping until you get -1, always providing the result of the previous call as the starting position. You can add each result in a List and convert that to...

In the second method you can use an AND operator to solve this problem. function brackets() { var testArr = ['()', '{}', '()']; /* Method 2 --- for loop. Same story, returns false, even when all testArr[i] === any of the cases and none of them is !==, it behaves...

That's because indexOf returns an index of matched element. If element not found, it will return -1. What you need is to change the condition: function process(argv1) { if(argv1.indexOf('test') !== -1) { console.log('Text is available in array.'); } } process(['test','one','help', 'one', 'two']); Edit: As pointed out @Havvy, in case of...

Iterating the elements is really an option, but if you don't like it, you may have 2 more options depending on your setup: The following code requires map function (check compatibility here, it basically requires IE9+) and slice function compatibility (same, IE9+). var fretdata = document.getElementById("fretinformation").getElementsByTagName("text"); alert([].slice.call(fretdata).map(function(o) { return o.textContent;...

The behavior makes perfect sense to me. You are using a combining character, which is combined with the preceding character, turning it into a different character, one which won't match the '\\' character you've specified at the end of your search string. That prevents the entire string you're looking for...

related question: Is there a version of JavaScript's String.indexOf() that allows for regular expressions? But only for a case sensitive is more easy to do: window.location.href.toLowerCase().indexOf("youtube.com/thumbnail?id=") ...

why not use a more efficientive method, such as KMP, BM ? The more advanced string search algorithms have a non-trivial setup time. If you are doing a once-off string search involving a not-too-large target string, you will find that you spend more time on the setup than you...

So, you want to return the indexes of first occurrences of distinct items? Maps can be really cool for these things, and in this case, all you want to actually remember is when was the first occurrence of each distinct element. import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public...

The first letter of the word is -1 instead of 0 No. The first letter of the word is denoted by the index 0. If indexOf does not find the letter h in the string Hond, that has a different reason: it uses a case-sensitive comparison. Yielding -1 for...

.indexOf() checks arrays for strings - in this case you are trying to match an array object (not a string). You can either use jQuery's $.inArray() method, or iterate through your card deck like this: var found = false; for ( var card in playingDeck ) { if (card[0] ==...

Well I'm not sure why, but it looks like my debugger was lying to me. I believe what was happening was the values in validPrefixes needed to all be lower case since I was using the ToLower() method previously in my code which effected the string addr variable. For some...

It's an expected result. FFFD is a "replacement character" in Unicode and is not meaningful in any culture. IndexOf ignores any non-meaningful characters in its search: Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. ...

You can use List.FindIndex: int index = list.FindIndex(obj => obj.X == value); The zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, –1. ...

You are not storing any object pointerss in the ComboBox itself, so you cannot use the ComboBox's own IndexOfObject() method. Not that it would work anyway, because IndexOfObject() searches for an object pointer, but you are looking for text instead. You will have to iterate the TStringList looking for the...

All these characters have corresponding ASCII codes, you can insert them in a string by escaping it. For instance: "App\x0000\x0001\x0000\x0003\x0000\x0000\x0000DB INFO" or shorter: "App\x00\x01\x00\x03\x00\x00\x00"+"DB INFO" \xXXXX means you specify one character with XXXX the hexadecimal number corresponding to the character. Notepad++ simply wants to make it a bit more convenient...

Array.indexOf() uses strict equality (===) to find an element. The elements of mapping are arrays and two distinct arrays that happen to have the same elements are not ===. I suspect that process_mapping_list() is returning an array that looks like one of the elements of mapping but is not the...

You are using an ArrayList of StringBuilderobjects. As StringBuilder is used for building strings, and not as actually Strings , you can't use indexOf(s), as the whole object itself should be equal to the one you are comparing so that it returns true. In order to solve this problem, you...

it is because calling .push() will return the new length of the array which is a number, so the second call prev will be a number(1) which don't have the push method. Returns The new length property of the object upon which the method was called. So using the if...

If you check the ArrayList.indexOf implementation, you will see that Vector3i.equals is called in your case. Actually it's even specified in JavaDoc for List: More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index. In general equals operation...

Use String's contains() method if you just need to check if a string contains another string. For example: if(hostName.toLowerCase().contains("." + TECK.name().toLowerCase() + ".")) Use String's split method if you need to check if a string is in a certain place in the hostname (e.g. before the first period, before the...

If dataStringTot.indexOf("\n") returns zero, then the first character of dataStringTot must be a newline character. In the context of your snippet, this points to dataStringTot starting with a newline before you start Alternatively dataStringTot could be "" before you start. For what it is worth, you could write that more...

Based on the comments and discussion here is my modified answer. First, there are two indexOf methods in JavaScript. One is the String Method indexOf, it returns the position of the first occurrence of a specified value in a string. Second is the Array Method indexOf, which searches an array...

Because Arrays.asList(bArr) is creating a List<boolean[]> not a List<Boolean>. Arrays.asList does not box your boolean[] array to a Boolean[] array (note the difference). Hence you only have a List with a single boolean array at index 0. If you used Boolean[] bArr = new Boolean[]{true, true, true, true, true};, index...

You may use the following example: var url = window.location.search; if (/searchTerm=bread$/.test(url)) { do stuff; } else if (/searchTerm=cheese\+slices$/.test(url)) { do stuff; } $ represent end of line. \ backslash is use to escape the special character like + Hope this help :)...