Thread: replacetext()
View Single Post
  #1  
Old 11-18-2008, 10:07 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
replacetext()

I tried Tig's replacetext, but I couldn't get it to work, so I had to create my own. I thought I'd post it here in case anyone wanted to use it.

PHP Code:
function replacetext(txt,a,b) {
  if (
txt.pos(a)<0) return txt;
  
temp.txtpos txt.positions(a);
  
temp.newtxt txt.substring(0,txtpos[0]);
  for (
temp.i=0;i<txtpos.size();i++) {
    
newtxt @= b;
    
newtxt @= txt.substring(txtpos[i]+a.length(),txt.substring(txtpos[i]+a.length()).pos(a));
  }
  return 
newtxt;

Functions simply via:

temp.test = replacetext("Hello\n \"world how\"\n\n are you?","\n",",");

will return Hello, "world how",, are you?(sorry I stole your thing, Tig!)

I don't know how efficient it is, but I got it working so I was happy with it.
Reply With Quote