Coastal Web
10-24-2006, 08:04 PM
Hello everyone,
I was hoping someone would be able to help me out with a javascript.
I need a javascript function that will take will take a string, a starting point, and ending point, and return the contents of the string between "starting point" and the "ending point".
For example:
var string = "this is a test string";
var myString = GetString(string, "is", "string"); //<- function l need created.
//as a result of the 'GetString()' function myString = "a test"
//when fed through the javascript function, that l need help with.
I've attached a php script that does the same thing, however l am in need of a javascript equivalent.
Here's a PHP example of what l need the javascript to do:
<?php
function GetString($source, $start, $end) {
$startInt = strpos($source,$start) + strlen($start);
$endInt = strpos(substr($source, $startInt, strlen($source) - $startInt), $end) + $startInt;
return substr($source, $startInt, $endInt - $startInt);
}
$myString = "this is a test string";
//returns: this is a test string
$shortStrin = GetString($myString, "is", "string");
//returns: a test
?>
I hope l've explained this enough, and one of you more seasoned javascript vets will be able to help me out with this.
Samantha G.
I was hoping someone would be able to help me out with a javascript.
I need a javascript function that will take will take a string, a starting point, and ending point, and return the contents of the string between "starting point" and the "ending point".
For example:
var string = "this is a test string";
var myString = GetString(string, "is", "string"); //<- function l need created.
//as a result of the 'GetString()' function myString = "a test"
//when fed through the javascript function, that l need help with.
I've attached a php script that does the same thing, however l am in need of a javascript equivalent.
Here's a PHP example of what l need the javascript to do:
<?php
function GetString($source, $start, $end) {
$startInt = strpos($source,$start) + strlen($start);
$endInt = strpos(substr($source, $startInt, strlen($source) - $startInt), $end) + $startInt;
return substr($source, $startInt, $endInt - $startInt);
}
$myString = "this is a test string";
//returns: this is a test string
$shortStrin = GetString($myString, "is", "string");
//returns: a test
?>
I hope l've explained this enough, and one of you more seasoned javascript vets will be able to help me out with this.
Samantha G.