Sign in to follow this  
Followers 0
AzKay

Javascript Alternative to _StringBetween

3 posts in this topic

Func __StringBetween($s, $from, $to)
    $x = StringInStr($s, $from) + StringLen($from)
    $y = StringInStr(StringMid($s, $x +1), $to)
    Return StringMid($s, $x, $y)
EndFunc

I tryed converting that to javascript, but I fail at javascript, Thus it failed.

Anyone have any ideas?


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites



function _stringBetween(sSource, sFrom, sTo) {
    sOutput = sSource
    
    iFrom = sOutput.indexOf(sFrom)
    if (iFrom == -1) return false
    sOutput = sOutput.substring(iFrom + sFrom.length, sOutput.length)
    
    iTo = sOutput.indexOf(sTo)
    if (iTo == -1) return false
    sOutput = sOutput.substring(0, iTo)
    
    return sOutput
}

sTest = 'Hello my name is Simon, I like to do drawings.'
alert(_stringBetween(sTest, 'my', 'to'))

Share this post


Link to post
Share on other sites

Thanks :3


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0