java替换字符串中特定字符

public class Find
{
	public static void main(String args[]) {
		String key = ",";
		String str = "6,035,45545445,55464,6456";
		StringBuilder strBuilder = new StringBuilder(str);
		int a = str.indexOf(key);
		while (a != -1) {
			/*System.out.print(a + "\t");*/
			strBuilder.setCharAt(a, '|');
			a = str.indexOf(key, a + 1);
		}
		str=strBuilder.toString();
		System.out.println(str);
        
	}
}

运行结果:
java替换字符串中特定字符_第1张图片
编译的过程中如果报错,就另存为一下,选择一下文件编码类型
java替换字符串中特定字符_第2张图片

你可能感兴趣的:(③,Java)