Skip to content

Instantly share code, notes, and snippets.

@Houdini
Created Aug 8, 2010
Embed
What would you like to do?
- (String) highlight_text:(String)input_string {
if (search_string !== '') { //search_string id defined before
var regex = new RegExp(search_string, 'ig');
var start_index = input_string.search(regex);
var new_substring = '<strong>' + intput_string.substring(start_index, search_string.length) + '</strong>';
return input_string(0, start_index) + new_substring + input_string(search_string.length + start_index, input_string.length);
} else {
return '';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment