Split Text and Replace Parts

[Total: 0    Average: 0/5]

Use split and replace to change patterns of strings.

Body Code:

If you know the spacing:<BR>
<script>
var _String="xxx xxxxx/xxx xxx xxxx/DHS";
var _split=_String.split("/");
document.write("0:"+_split[0]+"<BR>n");
document.write("1:"+_split[1]+"<BR>n");
document.write("2:"+_split[2]+"<BR>n");
document.write("<HR>");
var _split0=_split[0].split(" ");
document.write("0-0:"+_split0[0]+"<BR>n");
document.write("0-1:"+_split0[1]+"<BR>n");
document.write("<HR>");
var _split1=_split[1].split(" ");
document.write("1-0:"+_split1[0]+"<BR>n");
document.write("1-1:"+_split1[1]+"<BR>n");
document.write("1-2:"+_split1[2]+"<BR>n");
</script>
<HR>
If you don't know the spacing:<BR>
<script>
var _String="xxx xxxxx/xxx xxx xxxx/DHS";
var _split=_String.split("/");
for(i=0;i<_split.length;i++)
{
  document.write(i+":"+_split[i]+"<BR>n");
  var _split0=_split[i].split(" ");
  for(j=0;j<_split0.length;j++)
  {
    document.write(i+"-"+j+":"+_split0[j]+"<BR>n");
  }
}
</script>
<HR>
To replace spaces with dots:<BR>
<script>
var _str1="joe bloggs with more names";
while(_str1.indexOf(" ")!=-1)
 _str1=_str1.replace(" ",".");
document.write("NEW:"+_str1);
</script>

Times Viewed: 8

Leave a Reply

Your email address will not be published. Required fields are marked *