计算剪贴板里仿制的代码行数

[文件] ClipCodeCount.java ~ 1KB    下载(2) import java.awt.*;
import java.awt.datatransfer.*;
import java.io.*;
import java.util.regex.*;
public class ClipCodeCount {

	/**
	 * 正则表达式主要是匹配多行注释
	 */ http://www.fpshamen.com/linked/20130215.do; 
	private static Pattern pattern = Pattern.compile("/\\*([\\s|\\S]) ?\\*/");

	/**
	 * 计算文本中的代码行数 1.用正则表达式出去块注释即多行注释 2.再将字符串依照回车符分割成字符串数组 3.除掉空白行或许单行注释行
	 * 
	 * @param content
	 *            输入文本
	 * @return 文本中代码行数
	 */
	public static int getCodeCount(String content) {
		int rowCount = 0;
		Matcher matcher = pattern.matcher(content);
		content = matcher.replaceAll(" ");
		String ss[] = content.split("\n");
		for (String s : ss) {
			if (s.trim().length() > 0 
posted @ 2013-02-16 02:30  chinadiy197601  阅读(206)  评论(0编辑  收藏  举报