比较高效的关键字过滤代码

	public String keywordMask(String str) {
		StringBuffer buffer = new StringBuffer(str);
		for (String keyword : getKeyword()) {
			int index = 0;
			while (true) {
				index = buffer.indexOf(keyword, index);
				if (index < 0) {
					break;
				}
				for (int i = 0; i < keyword.length(); i++) {
					buffer.setCharAt(index + i, '*');
				}
			}
		}
		return buffer.toString();
	}
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">