Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the javascript equivalent function for vbscript Mid function? is that substring() or substr()?

Tags:

javascript

There are two javascript solutions for this,

1. String.substring(from,to) 
2. String.substr(from,length)

what is the most convenient solution for vb script Mid() function

like image 617
Madura Harshana Avatar asked Apr 12 '26 10:04

Madura Harshana


2 Answers

The method substr matches the usage of VB Mid function closest. The obvious difference is the the VB function takes a string as an argument, where the JS substr is a method of the string object.

string.substr(start,length)
like image 57
Aesthete Avatar answered Apr 14 '26 23:04

Aesthete


foo = "Hello World!".substr(2, 4);

is the same as

foo = Mid("Hello World!", 2, 4)
like image 39
JamesOR Avatar answered Apr 14 '26 23:04

JamesOR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!