I just implemented (in coffeescript) these javascript prototype methods but I got the feeling that there is a better way to implement them

```coffee
String::after                = (value         )-> if (@.indexOf(    value) == -1 or @.indexOf(    value) + value.size()     > @.size()) then '' else @.substring(@.indexOf(    value) + value.size())
String::after_Last           = (value         )-> if (@.lastIndexOf(value) == -1 or @.lastIndexOf(value) + value.size()     > @.size()) then '' else @.substring(@.lastIndexOf(value) + value.size())
String::before               = (value         )-> @.substring(0,@.indexOf(value))
String::before_Last          = (value         )-> @.substring(0,@.lastIndexOf(value))

```

Here are the tests I current have for these for methods:

```
it 'after',->
    value.after.assert_Is_Function()
    value.after('3'  ).assert_Is(''     )
    value.after('2'  ).assert_Is('3'    )
    value.after('123').assert_Is(''     )
    value.after('b'  ).assert_Is('c123' )
    value.after('bc1').assert_Is('23'   )
    value.after('xxx').assert_Is(''     )
    value.after(null ).assert_Is(''     )
    'abb'.after('b'  ).assert_Is('b'    )
    'a.b'.after('.'  ).assert_Is('b'    )
    'a.b.c'.after('.').assert_Is('b.c'  )

it 'after_Last',->
    value.after_Last.assert_Is_Function()
    value.after_Last('3'  ).assert_Is(''     )
    value.after_Last('2'  ).assert_Is('3'    )
    value.after_Last('123').assert_Is(''     )
    value.after_Last('b'  ).assert_Is('c123' )
    value.after_Last('bc1').assert_Is('23'   )
    value.after_Last('xxx').assert_Is(''     )
    value.after_Last(null ).assert_Is(''     )
    'abb'.after_Last('b'  ).assert_Is(''     )
    'a.b'.after_Last('.'  ).assert_Is('b'    )
    'a.b.c'.after_Last('.').assert_Is('c'    )

it 'before',->
    value.before.assert_Is_Function()
    value.before('3'  ).assert_Is('abc12')
    value.before('2'  ).assert_Is('abc1' )
    value.before('123').assert_Is('abc'  )
    value.before('b'  ).assert_Is('a'    )
    value.before('bc1').assert_Is('a'    )
    value.before('xxx').assert_Is(''     )
    value.before(null ).assert_Is(''     )
    'abb'.before('b'  ).assert_Is('a'    )
    'a.b'.before('.'  ).assert_Is('a'    )
    'a.b.c'.before('.').assert_Is('a'    )

it 'before_Last',->
    value.before_Last.assert_Is_Function()
    value.before_Last('3'  ).assert_Is('abc12')
    value.before_Last('2'  ).assert_Is('abc1' )
    value.before_Last('123').assert_Is('abc'  )
    value.before_Last('b'  ).assert_Is('a'    )
    value.before_Last('bc1').assert_Is('a'    )
    value.before_Last('xxx').assert_Is(''     )
    value.before_Last(null ).assert_Is(''     )
    'abb'.before_Last('b'  ).assert_Is('ab'   )
    'a.b'.before_Last('.'  ).assert_Is('a'    )
    'a.b.c'.before_Last('.').assert_Is('a.b'  )

```

I specifically don't like the **if** statements in the **after** and **after\_Last** methods

I'm also wondering if I'm missing a couple test cases for the **before** and **before\_Last** methods (since they are quite simple implementations :) )

These methods are part of <https://github.com/o2platform/fluentnode>

Update 1: here is using version from **Patrick J. S.**

```
String::after                = (value         )-> if ((index = @.indexOf(    value)) == -1 ) then '' else @.substr(index + value.size())
String::after_Last           = (value         )-> if ((index = @.lastIndexOf(value)) == -1 ) then '' else @.substr(index + value.size())

```

I also added these extra tests for the '' case:

```
value.after_Last (''   ).assert_Is(''      )
value.after(''         ).assert_Is('abc123')
value.before(''        ).assert_Is(''      )
value.before_Last(''   ).assert_Is('abc123')

```