剪切 jsoup 收到的字符串

Cut a string recieved by jsoup

所以这是我的代码,但是每次尝试剪切字符串 "words" 都失败了,它只是执行 TextView 以及 jsoup 收到的整个文本。

我只想剪切字符串的前 x 个单词。

public class main extends AppCompatActivity {
    TextView texx;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // braus();
    texx = (TextView) findViewById(R.id.textView);
    Button button = (Button) findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new http().execute();
        }
    });
}

public class http extends AsyncTask<Void, Void, Void> {
    String words;
    String test;

    @Override
    protected Void doInBackground(Void... params) {

        try {

            Document doc = Jsoup.connect("https://de.wikipedia.org/wiki/Wikipedia:Hauptseite").get();
            words = doc.text();
            words.substring(100);


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


        return null;
    }

    @Override
    protected void onPostExecute(Void aVoid) {
        super.onPostExecute(aVoid);

        texx.setText(words);

    }
}

}

这没有用:

words.substring(100);

是的,它产生了一个子字符串,但它随后立即丢弃了该子字符串,它没有对它做任何事情,因为您没有将结果分配给任何东西,而且它当然也不会改变 String 对象分配给 words 变量。也许你想要:

words = words.substring(100);

这将获取子字符串并将其分配回 words 变量。

这应该是你的口头禅:字符串对象是不可变的