-3

如何拆分字符串

'ABCDEFGHIJK'

我知道字符串的起点和终点

Startid endid
1       2
3       5
6       7
8       11

AS
-----

AB
CDE
FG
HIJK
4

5 回答 5

4
String s = string.subString(startpoint,endpoint);
于 2013-06-27T05:16:11.260 回答
1

stringVar.subString(sPoint,ePoint);

确保定期重置 sPoint 和 ePoint 的值

于 2013-06-27T05:21:36.157 回答
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 的类拆分(当然也可以是其他选项):

class Split {
    public int startid;
    public int endid;

    public Split(int startid, int endid){
        this.startid = startid;
        this.endid = endid;
    }
}
于 2013-06-27T05:26:20.537 回答
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++;
}
于 2013-06-27T05:30:28.867 回答
0
public static String getSubString(String myString,int statIndex,int endIndex){
       return myString.substring(statIndex,endIndex);
}
于 2013-06-27T05:30:57.957 回答