Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I was wondering if it were possible with jQuery to add together numbers in a string...

The strings can only be added to themselves as shown in the examples below. If one or more of the string appears, it should be combined.

All the possible strings: click here

Example with possible strings:

+0.53 attack damage
+0.53 attack damage
= 1.06 attack damage

+8.75 mana
+8.75 mana
= 17.5 mana

Each of these can be combined up to 9 times.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
159 views
Welcome To Ask or Share your Answers For Others

1 Answer

Iterate through the characters of the string (by making substrings with length 1); once you detect a number or a decimal point, save the start position in a variable. Then, once you detect something that is not a number or decimal point, or a second decimal point (count the number of decimal points), the number has ended; save the end position and voilà, you have the start and end position of the number and can get it by making a substring.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...