Jump to content

Javascript Alternative to _StringBetween


Recommended Posts

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- #
Link to comment
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'))

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...