本帖最后由 slience_缄默 于 2020-9-27 14:17 编辑 /**
* Alipay.com Inc.
* Copyright (c) 2004-2020 All Rights Reserved.
*/
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author wz
* @version : Demo.java, v 0.1 2020年09月27日 14:01 wz Exp $
*/
public class Demo {
private List<String> stringList = new ArrayList<>();
public void addLine(String line){
stringList.add(line);
}
public String getEntry(int row, int column){
String values = stringList.get(row);
String[] value = values.split(",");
if(value[column].split(""").length -1 != 0){
return value[column] + value[column+1];
}
return value[column];
}
public int rows(){
return stringList.size();
}
public int columns(){
String values = stringList.toString();
String[] value = values.split(",");
Pattern p1= Pattern.compile(""(.*?)"");
Matcher m = p1.matcher(values);
int count = 0;
while (m.find()) {
if((m.group().trim().contains(","))) count ++;
}
return value.length - count;
}
public static void main(String[] args) {
Demo demo = new Demo();
demo.addLine("John Jacob Astor,1763,1848");
demo.addLine(""William Backhouse Astor, Jr.",1829,1892");
demo.addLine(""John Jacob ""Jakey"" Astor VI",1912,1992");
System.out.println(demo.rows());
System.out.println(demo.columns());
System.out.println(demo.getEntry(0,0));
}
}
刚好今天上班比较闲,给你搞定了。
注意:字符串里的引号是有转义的,这里贴代码会把转义给去掉,你复制了代码这里需要转一下,"需要改成\" |