0

テキスト ファイルから読み取ろうとしていますが、これらの文字列は異なる属性に分かれていますが、最初の分割後にどのようにすればよいかわかりません。

これが私のコードです:getType()文字列のオフセットは何ですか?

try {
        InputStream is = context.getAssets().open("Autoeval");
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
         //Skips lines
        for (int i = 0; i< questionNumber; i++) {
            reader.readLine();
        }

        question = reader.readLine();

    } catch (IOException e) {
        e.printStackTrace();
    }
}



public String getId() {

    return question.substring(0, question.indexOf(";"));
}
public String getType() {
    return question.substring(question.indexOf(";"));
}
4

1 に答える 1

1

醜いですが、2つのグローバルプライベート変数を作成してみませんか。

private String _id;
private String _type;

次に、質問を読んだ後、これを行うことができます:

{
    //stuff

    question = reader.readLine();

    _id = question.substring(0, question.indexOf(";"));
    _type = question.substring(_id.length); // assuming no other ";" delimiters

}

public String getId() {
    return _id;
}

public String getType() {
    return _type;
}

とはいえ、これを行うにはもっと良い方法があります。

于 2013-01-30T00:18:14.653 に答える