高分求一段JAVA字符串处理代码
要求是这样的,一个字符串str,其中出现了N次“@parameter”,给定一个int参数n,一个字符参数parameter,求一段代码,将str中第n个“@parameter”替换成parameter,其余的不变,类似数据操作ParapareStatement中的setString等操作,我想了很久。。。
/**
* 这是一个替换连续相同字符串中指定字符串的方法
* @author denghanyi
*
*/
public class Replace {
private static String str = "@parameter@parameter@parameter@parameter@parameter@parameter";
public String replace(int n,String parameter) {
String[] temp = str.split("@");
for(int i = 1;i < temp.length;i++) {
if(i == n) {
temp[i] = parameter;
}
else
temp[i] = "@" + temp[i];
}
String a = "";
for(int i = 1; i < temp.length;i++) {
a += temp[i];
}
return a;
}
public static void main(String[] args) {
Replace re = new Replace();
str = re.replace(4, "parameter");
System.out.println(str);
}
}
/**
* 这是一个替换连续相同字符串中指定字符串的方法
* @author denghanyi
*
*/
public class Replace {
private static String str = "@parameter@parameter@parameter@parameter@parameter@parameter";
public String replace(in
相关问答:
不知道是什么原因,我该如何处理,请大虾们指教了,小弟在此谢过。。。。
错误信息如下:
The program being debugged was signaled while in a function called from GDB.
GDB has restored the context t ......
字符流的读和写最终在底层都是通过字节流来完成的吗? 读写文本文件字符流应该就可以了吧。。
各位大哥大姐帮帮忙阿
Java流包括字节流和字符流,字节流通过IO设备以字节数据的方式读入,而字符流则是通过字节流 ......
我想使用Lucene的代码,发现要import一批文件:
============
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
………………
===== ......
1 public class BirthDate {
2 private int day;
3 private int month;
4 private int year;
5
6 public BirthDate (){}
7
8 public BirthDate (int d,int m,int y){
9 day = d;
......
为什么我用BufferWriter比不用花费的时间还要多?
而用BufferOutputStream时比不用效率要高十几倍
是不是我的代码有问题
请高手给个解释
Java code:
import java.io.*;
public class BufferCha ......