Question: This is what I have in my web part `.ascx` file:

```
var _SVR = BellMedia.videoCarousel.videoHub({
    containerDiv: "carousel-<%= this.InstanceGuid %>",
    templateDiv: "small-video-rotator",
});

```

And this is what i have in the `bellmedia.videoCarousel.videoHub.js`:

```
var BellMedia = BellMedia || {};
BellMedia.namespace('BellMedia.videoCarousel');

(function ($, _, utils) {
    BellMedia.videoCarousel.videoHub = function (options) {
        var intInterval = 0,
        isPlayerReady = false,
        //MORE CODE HERE
    }        
    };
})(jQuery, _, BellMedia.bravo.utils);

```

I included `bellmedia.videoCarousel.videoHub.js` in the web part file. 

And as you can see, the `videoHub` function is defined. But I am still getting the "videoHub" method not found message in Chrome Developer Tool Bar. 

Any help is greatly appreciated.
Thanks.

Answer: 
As I mentioned in comments, the mistake is that you are not skipping `len(x)` characters after match. Also `in` keyword is quite high-level routine (it does not less than **search** part of **search & replace**), so here is fixed version without `in`:

```
def rep_str(string, search, replacement):
    result = ''
    i = 0
    while i < len(string):
        if string[i : i + len(search)] == search:
            result += replacement
            i += len(search)
        else:
            result += string[i]
            i += 1
    return result

```
If you just want to have the result try with:

```
import re
re.sub(r'IN','aa','IN GOING GO')

```

but if you need some logic then you should compare for blocks of same length as the pattern, not char by char

@Zag asnwer is better, because can compare longer patterns and has return when it does not match nothing but if you want to get your code running you need to skip for when you have a match like this : 

```
def rep_str(s,x,y):
    result=""
    skip = False
    if x in s:
        for i in range(len(s)):
            if skip:
                skip = False
                continue
            if s[i:i+2] == x:
                result+=y
                skip = True
            else:
                result+=s[i:i+1] 
        return result
    else:
        return s

```

but your code won't work when you will call the function with `rep_str("A example test","test", "function")` for example.