我有一个c++方法extractField,我想用它从一行中的每个字段中以axtract分隔某些字段,在'\t'中它可以很好地在c++中使用,有人可以帮助我使用Java语法。我想应用一个模拟器method_ here是我所拥有的:

    String ExtractField(String aline,int fieldnumber){
    Int seppos;
    String field;
    for (int fld = 0: fld< fieldnumber;fld++){
      seppos = aline.Pos('\t');
      field = aline.SubString(1,seppos-1);
      aline.delete(1.seppos);
    }
     If(seppos>0){return field;}
     else{return aline;}
    }

最佳答案

以下是java中的内容,为您重写了它;)

private String ExtractField(String aline, int fieldnumber)
{
    Integer seppos = new Integer();
    String field;
    for (int fld = 0; fld < fieldnumber; fld++)
    {
      seppos = aline.indexOf('\t');
      field = aline.substring(1, seppos - 1);
      //aline.delete(1.seppos); what does this do?
    }
     If(seppos > 0)
     {
         return field;
     }
     else
     {
         return aline;
     }
}

09-11 18:47