--- basic/source/runtime/rtlproto.hxx.orig	2007-11-20 16:12:58.000000000 -1000
+++ basic/source/runtime/rtlproto.hxx	2007-11-20 16:14:47.000000000 -1000
@@ -189,6 +189,7 @@ extern RTLFUNC(Log);
 extern RTLFUNC(LTrim);
 extern RTLFUNC(Mid);
 extern RTLFUNC(Oct);
+extern RTLFUNC(Replace);
 extern RTLFUNC(Right);
 extern RTLFUNC(RTrim);
 extern RTLFUNC(RTL);
--- basic/source/runtime/stdobj.cxx.orig	2007-11-20 16:13:11.000000000 -1000
+++ basic/source/runtime/stdobj.cxx	2007-11-20 16:26:57.000000000 -1000
@@ -444,6 +444,13 @@ static Methods aMethods[] = {
   { "Red",       	SbxINTEGER, 0,NULL,0 },
   { "Green",       	SbxINTEGER, 0,NULL,0 },
   { "Blue",       	SbxINTEGER, 0,NULL,0 },
+{ "Replace",        SbxSTRING,    6 | _FUNCTION, RTLNAME(Replace),0         },
+  { "Expression",   SbxSTRING, 0,NULL,0 },
+  { "Find",     	SbxSTRING, 0,NULL,0 },
+  { "Replace",      SbxSTRING, 0,NULL,0 },
+  { "Start",        SbxINTEGER, 	_OPT, NULL,0 },
+  { "Count",        SbxINTEGER,		_OPT, NULL,0 },
+  { "Compare",      SbxINTEGER,		_OPT, NULL,0 },
 { "Right",          SbxSTRING,    2 | _FUNCTION, RTLNAME(Right),0           },
   { "String",       SbxSTRING, 0,NULL,0 },
   { "Count",        SbxLONG, 0,NULL,0 },
--- basic/source/runtime/methods.cxx.orig	2007-11-20 16:13:25.000000000 -1000
+++ basic/source/runtime/methods.cxx	2007-11-20 16:48:10.000000000 -1000
@@ -1348,6 +1348,87 @@ RTLFUNC(Oct)
 	}
 }
 
+// Replace(expression, find, replace[, start[, count[, compare]]]) 
+
+RTLFUNC(Replace)
+{
+    (void)pBasic;
+    (void)bWrite;
+    
+	ULONG nArgCount = rPar.Count()-1;
+	if ( nArgCount < 3 || nArgCount > 6 )
+		StarBASIC::Error( SbERR_BAD_ARGUMENT );
+	else
+	{
+		String aExpStr = rPar.Get(1)->GetString();
+		String aFindStr = rPar.Get(2)->GetString();
+		String aReplaceStr = rPar.Get(3)->GetString();
+
+		INT32 lStartPos = 1;
+		if ( nArgCount >= 4 )
+		{
+			lStartPos = rPar.Get(4)->GetLong();
+			if( lStartPos < 0  || lStartPos > 0xffff )
+			{
+				StarBASIC::Error( SbERR_BAD_ARGUMENT );
+				lStartPos = 1;
+			}
+			lStartPos = lStartPos ? lStartPos : 1;
+		}
+
+		INT32 lCount = -1;
+		if( nArgCount >=5 )
+		{
+			lCount = rPar.Get(5)->GetLong();
+			if( lCount < -1 || lCount > 0xffff )
+			{
+				StarBASIC::Error( SbERR_BAD_ARGUMENT );
+				lCount = -1;	
+			}
+			lCount = lCount ? lCount : -1;
+		}
+
+		SbiInstance* pInst = pINST;
+		int bTextMode;
+		bool bCompatibility = ( pInst && pInst->IsCompatibility() );
+		if( bCompatibility )
+		{
+			SbiRuntime* pRT = pInst ? pInst->pRun : NULL;
+			bTextMode = pRT ? pRT->GetImageFlag( SBIMG_COMPARETEXT ) : FALSE;
+		}
+		else
+		{
+			bTextMode = 1;
+		}
+		if ( nArgCount == 6 )
+			bTextMode = rPar.Get(6)->GetInteger();
+
+		USHORT nStrLen = aExpStr.Len();
+
+		if( lStartPos <= nStrLen )
+		{
+			String aSrcStr( aExpStr );
+			if( bTextMode )
+			{
+					aSrcStr.ToUpperAscii();
+					aFindStr.ToUpperAscii();
+			}
+			
+			USHORT nPos = aSrcStr.Search( aFindStr, lStartPos - 1 );
+			USHORT nCounts = 0;
+			USHORT nReplaceLength = aReplaceStr.Len() ? aReplaceStr.Len():1;
+			while( nPos != STRING_NOTFOUND && (lCount == -1 || lCount > nCounts) )
+			{
+				aExpStr.Replace( nPos, aFindStr.Len(), aReplaceStr );
+				nPos += nReplaceLength;
+				nPos = aSrcStr.Search( aFindStr, nPos );
+				nCounts++;
+			}
+		}
+		rPar.Get(0)->PutString( aExpStr.Copy(lStartPos - 1)  );
+	}
+}
+
 RTLFUNC(Right)
 {
     (void)pBasic;
