| |

VerySource

 Forgot password?
 Register
Search
View: 11|Reply: 3

Ask ~~~ to extract the characters in the string

[Copy link]

1

Threads

1

Posts

2

Credits

Newbie

Rank: 1

Credits
2

 China

Post time: 2020-3-4 23:30:01
| Show all posts |Read mode
In a string of characters, how to extract this string of characters with JS,
Such as xxxxxx1111; know the length of xxxxxx, extract xxxxxx and 1111 respectively, prawn help
Reply

Use magic Report

0

Threads

1

Posts

2

Credits

Newbie

Rank: 1

Credits
2

 China

Post time: 2020-5-20 20:00:02
| Show all posts
<script language = javascript>
var str = '123'
alert (str.substr (0,1))
alert (str.substring (0,2))
</ script>
Reply

Use magic Report

0

Threads

4

Posts

5

Credits

Newbie

Rank: 1

Credits
5

 China

Post time: 2020-5-25 11:00:01
| Show all posts
javascript: var s = "xxxxxx1111"; var sm = s.match (/ x * /); var sm_s = sm.index; var sm_l = sm.lastIndex; var si = sm.input; alert (si.substring (sm_s , sm_l) + sm_l + si.substring (sm_l, si.length)); void (0)
Just run it in the browser and you have the answer
Reply

Use magic Report

0

Threads

10

Posts

10

Credits

Newbie

Rank: 1

Credits
10

 China

Post time: 2020-6-21 22:15:01
| Show all posts
You can use regular expressions
var str = "aaaaaaaa1111";
var test = /([a-zA-Z]{8})([0-9]{4})/
Then extract Group 1 and Group 2 separately, you can go to Google to find out how to achieve it. This is faster and better than substring in speed.

Another way:
Use substring()
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