indexof

Knockout JS: indexOf always returns -1?

青春壹個敷衍的年華 提交于 2019-12-11 02:50:24
问题 Background I'm trying to build a gradebook app, mostly as a learning exercise. Currently, I have two models, a student, and an assignment. I decided to store all score-related information inside the student rather than with each assignment. Perhaps there's a better approach. Regardless, I already have the average score for each student, i.e., her grade in the class. I'm now at the point where I want to calculate the average score on each assignment. This is where I run into trouble, as it's

How do I make letters to uppercase after each of a set of specific characters

北城余情 提交于 2019-12-11 02:46:19
问题 I have a collection of characters (',', '.', '/', '-', ' ') then I have a collection of strings (about 500). What I want to do as fast as possible is: after each of the characters I want to make the next letter uppercase. I want the first capitalized as well and many of the strings are all uppercase to begin with. EDIT: I modified tdragons answer to this final result: public static String CapitalizeAndStuff(string startingString) { startingString = startingString.ToLower(); char[] chars = new

toString() for each element of an array in Javascript [duplicate]

筅森魡賤 提交于 2019-12-10 22:39:49
问题 This question already has answers here : A loosely-typed indexOf()? (3 answers) Closed 4 years ago . I want to find whether an element, that might be a string OR a number, is inside an array. The array is test and the element is value . So far so good, I have this code: function compare(value, test) { // We need to stringify all the values to compare them with a string return test.map(function(value){ return value.toString(); }).indexOf(value) > -1; } alert(compare("2", [1, 2, 3])); alert

How to conditionally disable an object within an array in Angular

做~自己de王妃 提交于 2019-12-10 16:35:47
问题 I have several select elements on the same page. Each select dropdown contains the same items. I would like to disable an item within the dropdown if it has already been selected in another select element. In other words, I don't want an item to be selected more than once across all of the select elements. Any thoughts on how to accomplish this? When I use the following code, nothing is disabled in the dropdown. Code for controller: var editProject = this; editProject.addMore = function() {

why is string IndexOf() acting case-INsensitive?

江枫思渺然 提交于 2019-12-10 15:19:27
问题 I'm really stumped by this one. I'm learning LINQ and used Microsoft Visual C# Express Edition to connect to a SQL Server database containing information about my books. I created the LINQ to SQL classes as needed. That stuff obviously works. It all works except I cannot figure out for the life of me why, if I search for "SR" (uppercase), it finds two records, "SR-71 Revealed, The Inside Story", as expected, but it also finds "Faded Sun: Kesrith" where the "sr" is lowercase. I'm using the

Javascript indexOf method with multiple values

人走茶凉 提交于 2019-12-10 14:52:10
问题 I have an array wich contains multiple same values ["test234", "test9495", "test234", "test93992", "test234"] Here I want to get the index of every test234 in the array For that I've tried Array.prototype.indexOf() method. But It only returns me 0 but I want it to return me [0, 2, 4] . How can I do that? var array = ["test234", "test9495", "test234", "test93992", "test234"]; document.write(array.indexOf("test234")); 回答1: Just make it a for loop to check each array element. var array = [

Javascript .indexOf not working on an int array

杀马特。学长 韩版系。学妹 提交于 2019-12-10 12:46:07
问题 Code: function showlayer(name){ var size = js_array.length var index = js_array.indexOf(name); var plusOne = js_array[index+1]; document.write("" + name + "<br />" + js_array + "<br />" + index + "<br />" + plusOne + "<br />" ) ... } Output: 301 300,299,301,290,303,304,302,310,291,306,308,305,307,292,294,295,309 -1 300 All possible values of name are in the array, but for some reason indexOf() never finds them. Whats up? 回答1: Try this instead: ... var index = js_array.indexOf(parseInt(name,

subtract java text string

蓝咒 提交于 2019-12-10 11:54:33
问题 I want to extract the reference from an URL. For example, my URL looks like: "https://www.amazon.es/Lenovo-YOGA-520-14IKB-Ordenador-convertible/dp/B071WBF4PZ/" I want to get only the reference part, that is B071WBF4PZ I also want to extract the price from this html element: "<div id="cerberus-data-metrics" style="display: none;" data-asin="B078ZYX4R5" data-asin-price="1479.00" data-asin-shipping="0" data-asin-currency-code="EUR" data-substitute-count="0" data-device-type="WEB" data-display

indexOf to find all occurrences of a word in a String

不想你离开。 提交于 2019-12-10 10:37:29
问题 I'm trying to use indexOf to find all occurrences of the characters 'the' in a sentence. For example, if the sentence were "The other day I went over there", it should return 3. I am able to do this up to the point where it finds the first index, but I'm unsure of how to write the loop. I originally had a for loop that searched the entire string, but it was returning the full string character length, instead of the occurrences of my specified character. How can I write a loop that will find

Swift - Finding a substring between two locations in a string

半城伤御伤魂 提交于 2019-12-10 10:29:23
问题 I have a string that is formatted like this: "XbfdASF;FBACasc|Piida;bfedsSA|XbbnSF;vsdfAs|" Basiclly its an ID;ID| and then it repeats. I have the first ID and I need to find it's partner Example: I have 'Piida' and I need to find the String that follows it after the ';' which is 'bfedsSA' How do I do this? The problem I am having is that the length of the IDs is dynamic so I need to get the index of '|' after the ID I have which is 'Piida' and then get the string that is between these