Hi Chip,

Try the following and it should be done in a second or 2 (compiled).

  //ES_ReplaceStr_Shrink($source;$oldString;$newString;{$count 
pointer})->Resulted text
C_TEXT($0;$1;$2;$3;$source;$oldStr;$newStr;$result;$tempTxt)
C_POINTER($4)
C_LONGINT($oldLen;$newLen;$oldStrLen;$NewStrLen;$count;$offset;$offset2;$start;$pos)
C_BLOB($blob;$blob2)
$source:=$1
$oldLen:=Length($source)  //$source is the source text
$oldStr:=$2
$newStr:=$3
$oldStrLen:=Length($oldStr)
$newstrlen:=Length($newStr)

SET BLOB SIZE($blob;$oldlen*2+9;0)
$offset:=9
$start:=1
$count:=0
Repeat 
$pos:=Position($oldstr;$source;$start;*)
If ($pos>0)
$tempTxt:=Substring($source;$start;$pos-$start)+$newStr
$start:=$pos+$oldStrLen
If (Length($tempTxt)>0)
$offset2:=0
VARIABLE TO BLOB($tempTxt;$blob2;$offset2)
COPY BLOB($blob2;$blob;9;$offset;$offset2-9)
$offset:=$offset+$offset2-9
End if 
$count:=$count+1
End if 
Until ($pos=0)

If ($count>0)
If ($start<=$oldlen)
$tempTxt:=Substring($source;$start)
If (Length($tempTxt)>0)
$offset2:=0
VARIABLE TO BLOB($tempTxt;$blob2;$offset2)
COPY BLOB($blob2;$blob;9;$offset;$offset2-9)
End if 
End if 
If ($oldStrlen>$NewStrLen)
$newLen:=$oldLen+(($NewStrLen-$oldStrLen)*$count)
SET BLOB SIZE($blob;$newlen*2+9)
Else 
$newlen:=$oldLen
End if 

$blob{0x0000}:=Character code("R")
$blob{0x0001}:=Character code("V")
$blob{0x0002}:=Character code("L")
$blob{0x0003}:=Character code("B")
$blob{0x0004}:=0x0021
$blob{0x0005}:=$newlen%256
$blob{0x0006}:=($newlen\256)%256
$blob{0x0007}:=($newlen\65536)%256
$blob{0x0008}:=($newlen\16777216)
$offset:=0
BLOB TO VARIABLE($blob;$result;$offset)
$0:=$result

Else 
$0:=$1
End if 

If (Count parameters>3)
$4->:=$count
End if 

Alan Chan

4D iNug Technical <4d_tech@lists.4d.com> writes:
>$Source:=Replace String($Source;Char(9);"";*)
>
>Doesn't look so bad, does it?
>Turns out there are over 550,000 tabs in the text.
>Replace String, did indeed (eventually) return, but it took about 30 
>minutes.

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**********************************************************************

Reply via email to