javascript - Jquery selecting text between parentheses in an array -
I have based on values selected from multiple selection boxes:
Duration 03 (-1000), 1 (+1000), value (+3000), 1 (+1500), -, -, -, -, -, -, -, -, -, - - -, -, -, - , -, -, -, -, -
separated by commas, as you can see, some values have text in parentheses. I need to take these values in brackets and sum them, so we should keep the +
and -
characters.
Value (+1000), (+3000), (-1000) represent a change in value: + indicates that the product will be more expensive - the product's representation will be cheaper. The result should be a number that indicates the change in value - e.g. 1500 - The product will cost more than the original value, or eg. -3000 - The product will be cheaper. Thanks in advance. Tom
If you are not great with regular expressions then I have created a version that is not "usable" It makes them look more like this more readable and easy to see what's going on and how it is doing. You should not use regular expressions to say no.
For this algorithm we are basically looking for each item, checking that they have valid brackets, if we have +
otherwise if we have -
, we subtract (believe that they are only two that you may have):
for (items in the array) {first first = Array [items] Index ("(" "); var second mercury = array [item] .indexOf (") "); // check the item is bracket and in this way (...) if ((first page & gt; 0 & Amp; amp; amp; amp;; & amp; amp ;; second & gt; 0) & amp; amp; amp; amp; amp; second part & gt; firstpierce] string from var value = array [items]. Substring (prefix + 2, second page); value to = parseInt (value); // if number (array [items] .charAt (firstmost + 1) == '+') Product value + = value; // If "+" Enter other product - = value; // if "-" subtract it}}
Comments
Post a Comment