| |

VerySource

 Forgot password?
 Register
Search
View: 8|Reply: 1

js string filtering problem

[Copy link]

1

Threads

1

Posts

2

Credits

Newbie

Rank: 1

Credits
2

 China

Post time: 2020-3-20 16:30:01
| Show all posts |Read mode
My function received a string such as 789-456-1101 how to filter out "-"
Becomes 789,456,101
The book above is stored in a string
Then I got this book how to multiply each 2 and then add up
Such as 7 * 2 + 8 * 2 + 9 * 2 + 4 * 2 + 5 * 2 + 6 * 2 + 1 * 2 + 1 * 2 + 0 * 2 + 1 * 2

Thank you! By the way, is this a string or a character array?

And don't just talk about what to do, write a short code for reference!
Reply

Use magic Report

0

Threads

2

Posts

3

Credits

Newbie

Rank: 1

Credits
3

 China

Post time: 2020-6-26 21:00:01
| Show all posts
Go to "-" you can do it yourself, you can use replace or split

var str[] = "787895610".split("|");

var sb = "";
for(var i=0;i<str.length;i++){
    sb = sb + str[i] + "* 2"
    if(i != str.length-1){
          sb = sb + "+";
    }
}
var result = eval(sb);
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2020|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list