【问题标题】:Android Replace StringsAndroid 替换字符串
【发布时间】:2012-12-10 17:37:33
【问题描述】:

从活动中检索数据时如何替换字符串?我似乎无法在谷歌上找到它。也许我的问题太简单了。请看下面的代码。

Intent in = getIntent();
textToPass = in.getStringExtra("textToPass");

textToPass 实际上是一个字符串,例如。 "ExampleText.txt"

如何删除 .txt 使其看起来像“ExampleText”

我可能在附近,但我还是想不通

String exampletext = textToPass.getText().toString().replace(".txt","");

【问题讨论】:

标签: android


【解决方案1】:

这里的 textToPass 是字符串,因此您可以直接对其应用替换方法。

textToPass.replace(".txt","");

【讨论】:

  • 谢谢。现在明白了。解锁后会接受你的回答。
【解决方案2】:
Intent in = getIntent();
String textToPass = in.getStringExtra("textToPass");
String[] exampletext = textToPass.split("//.");

然后使用 exampletext[0] 它必须给出你期望的结果

【讨论】:

    猜你喜欢
    • 2013-09-02
    • 2012-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-26
    • 2015-02-28
    相关资源
    最近更新 更多