如何分割字符串
' ABCDEFGHIJK'
我知道字符串的起点和终点
Startid endid
1 2
3 5
6 7
8 11
AS
-----
AB
CDE
FG
HIJK
答案 0 :(得分:4)
String s = string.subString(startpoint,endpoint);
答案 1 :(得分:1)
stringVar.subString(SPOINT,ePoint);
确保定期重置sPoint和ePoint的值
答案 2 :(得分:0)
final String toSplit = "ABCDEFGHIJK";
for(final Split split : splits){
if(null != split){
if(0 <= split.startid && split.startid < toSplit.length() && 0 <= split.endid && split.endid < toSplit.length()){
return toSplit.substring(startid, endid);
}
}
return StringUtils.EMPTY;
}
假设包含你的startid / endid的类Split(当然可能是其他选项):
class Split {
public int startid;
public int endid;
public Split(int startid, int endid){
this.startid = startid;
this.endid = endid;
}
}
答案 3 :(得分:0)
根据您想要的表格
String s = string.subString(startpoint-1,endpoint-1);
如果您愿意,可以滥用课程Point(最好只创建自己的对象),请执行以下操作
String s = "ABCEDEFG..." // you string
// Create a list of your points (start and end)
List<Point> list = new ArrayList<Point>();
// Add your points
list.add(new Point(1,2));
list.add(new Point(3,5)); //etc
// Then do this to get your substring
String[] splits = new String[list.size()]
int i= 0;
for(Point p: list)
{
splits[i] = s.substring(p.getX()-1, p.getY()-1)
i++;
}
答案 4 :(得分:0)
public static String getSubString(String myString,int statIndex,int endIndex){
return myString.substring(statIndex,endIndex);
}