gpt4 book ai didi

java - 剪切 jsoup 接收到的字符串

转载 作者:行者123 更新时间:2023-11-30 00:46:07 31 4
gpt4 key购买 nike

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

我只想剪切字符串的前 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.substring(100);

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

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

关于java - 剪切 jsoup 接收到的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41780683/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com