在java中,在字符串中查找字符很方便。
以下示例:
string file content=" thisisaflashcallhtmlthisflashfile=SD card/inital flash.swf ";
可以通过以下方法在名为fileContent的字符串中查找名为tempflash的字符串:
pattern pattern=new pattern.com plie (" initial flash " ); //它用于设置匹配字符串,也可以是正则表达式。
设定用哪个字符串检索要检索的字符串——
matcher matcher=pattern.matcher (文件内容);
匹配成功后,可以更换。
stringtargetfilecontent=matcher.replace first (“临时闪存”)
这样就完成了字符串的搜索和替换。
但是,必须导入两个软件包:
import java.util.regex.Matcher;
import java.util.regex.Pattern;