当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
计算机二级辅导:java文本替换
发布时间:2010/3/13 9:05:16 来源:城市学习网 编辑:MOON
  public class test {
  public static String stringReplace(String str, String oldStr, String newStr) {
  String returnStr = "";
  int i, j, t, m, n;
  n = 0;
  j = oldStr.length();
  if (str.indexOf(oldStr) -1) {
  while (str.indexOf(oldStr, n) -1) {
  i = str.length();
  if (str.indexOf(oldStr) 0) {
  str = newStr + str.substring(j, i);
  } else {
  t = str.indexOf(oldStr);
  m = t + j;
  str = str.substring(0, t) + newStr + str.substring(m, i);
  n = t + newStr.length() - j + 1;
  }
  }
  }
  returnStr = str;
  return returnStr;
  }
  public static void main(String args) {
  String str="html/html";
  str=stringReplace(str,"","<");
  str=stringReplace(str,"",">");
  System.out.println(str);
  }
  }
  :
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved