您的位置:首页 > 编程语言

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

2013-02-16 02:30 176 查看
[文件] 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: