If you want to create a helper method for this, a good place would be /edx-platform/common/djangoapps/util/string_utils.py