Sparkle’s Workshop

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

Posted on July 26, 2007 - Filed Under Uncategorized |

	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();
	}

Most Commented Posts

Comments

Leave a Reply