Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用JAVA/ANDROID文本框中的内容替换文件中的字符串_Java_Android_Textbox_Replace - Fatal编程技术网

用JAVA/ANDROID文本框中的内容替换文件中的字符串

用JAVA/ANDROID文本框中的内容替换文件中的字符串,java,android,textbox,replace,Java,Android,Textbox,Replace,我用“replaceall”函数做了一些实验来改变文件的内容。但我想知道是否有可能用文本框中的文本替换字符串 例如: File: NAME: JOHN DOE GRADES:BLAH BLAH BLAH BLAH NAME: JOHN DOE GRADES2: BLAH BLAH BLAH NAME: JOHN DOE GRADES3:BLAH BLAH BLAH 然后我想在一个文本框中输入另一个“名字”来替换所有的“约翰·多伊的”,例如:“绿巨人霍根” 文件: 这可能吗 提前谢谢。当然

我用“replaceall”函数做了一些实验来改变文件的内容。但我想知道是否有可能用文本框中的文本替换字符串

例如:

File:

NAME: JOHN DOE
GRADES:BLAH BLAH BLAH BLAH

NAME: JOHN DOE
GRADES2: BLAH BLAH BLAH

NAME: JOHN DOE
GRADES3:BLAH BLAH BLAH
然后我想在一个文本框中输入另一个“名字”来替换所有的“约翰·多伊的”,例如:“绿巨人霍根”

文件:

这可能吗


提前谢谢。

当然可以,只要把旧字符串换成新字符串就行了

TextView tv; //Get the pointer to the textbox, included for definition
String text=tv.getText();
tv.setText(text.replaceAll(....));

例如(假设您有一个id为
TextView
TextView


对于
EditText
s

也可以使用类似的方法:

String myName = myEditText.getText().toString();
myText.replaceAll("John Doe", myName);

是的,这完全有可能。嘿!谢谢这一个成功了。我将其与一个“按钮”合并,以启动“替换”并将更改保存到一个新文件中,但当按下该按钮时,“文件内容”会被复制到文本框中。有办法解决这个问题吗?(保存部分正常工作)如果您的方法与我概述的方法相同,请省略
t.setText(替换)。如果文本在每次更新该文件时自动设置,则应将旧文本的副本保存在单独的
字符串中!谢谢。非常感谢您的回复。这对我帮助很大。
TextView tv; //Get the pointer to the textbox, included for definition
String text=tv.getText();
tv.setText(text.replaceAll(....));
TextView t = (TextView) findViewById (R.id.textView);
String text = t.getText().toString();
String replaced = text.replaceAll (/*your implementation*/);
t.setText (replaced);
String myName = myEditText.getText().toString();
myText.replaceAll("John Doe", myName);