Posted on 2007. 9. 10. 10:15
Filed Under Java

Javascript
<script language="javascript">
str = "abcd";
restr = "ab";
newstr = str.replace(restr, "xx");
document.wrtie(newstr);
</script>
출력결과 : xxcd


JSP
<%
String strReplace(String str, String restr, String newstr) {
  if(str = null) return null;
  StringBuffer dest = new StringBuffer("");
  try {
    int len = restr.length();
    int strlen = str.length();
    int pos = 0;
    int repos = 0;

    while ((pos = str.indexOf(restr, repos)) >= 0) {
      dest.append(str.substring(repos, pos));
      dest.append(newstr);
      repos = pos + len;
    }
    if (repos < strlen)
      dest.appen(str.substring(repos, strlen));
  } catch (Exception e) {
    e.printStackTrace();
  }
  return dest.toString();
}
%>

strReplace("abcd", "ac", "xx");

출력결과 : xxcd



Posted on 2007. 9. 6. 15:15
Filed Under 카테고리 없음

<script type="text/javascript">
function changeSelect(obj1,obj2) {
    obj1.onchange=function() {}
    if (obj2.name=="big") {
        obj2.onchange=function() { changeSelect(obj2,document.all.namedItem("medium")); }
    } else if (obj2.name=="medium") {
        obj2.onchange=function() { changeSelect(obj2,document.all.namedItem("third")); }
    } else if (obj2.name=="third") {
        obj2.onchange=function() { changeSelect(obj2,document.all.namedItem("forth")); }
    } else if (obj2.name=="forth") {
        obj2.onchange=function() { changeSelect(obj2,document.all.namedItem("big")); }
    }
    for (var i=1; i<obj1.options.length; i++) {
        if (i!=obj1.selectedIndex) {
            obj2.options.appendChild(obj1.options[i].cloneNode(true));
        }
    }
}
</script>
<SELECT name=big onChange="changeSelect(this,document.all.namedItem('medium'))">
    <OPTION>첫번째
    <OPTION value=cost>비용
    <OPTION value=time>시간
    <OPTION value=info selected>정보
    <OPTION value=service>서비스</OPTION></SELECT>
<SELECT name=medium> <OPTION selected>두번째</OPTION></SELECT>
<SELECT name=third> <OPTION selected>세번째</OPTION></SELECT>
<SELECT name=forth> <OPTION selected>네번째</OPTION></SELECT>

About

by 청지인

Notice

Counter

· Total
:
· Today
:
· Yesterday
: