Apache OpenOffice (AOO) Bugzilla – Issue 94895
BASIC-Function replace
Last modified: 2016-04-19 01:17:50 UTC
Replace result is wrong if sourcetext has more than one text parts to replace and len(sourecetxt) is changed Replace("und \(denke an die Klammer\) was der parser macht", "\", "") result und (denke an die Klammer\ was der parser macht Gruß HW
STARTED, 3.x
In OOo 3.3.0 the function appears to be working much better. ' all these are OK : MsgBox Replace("und \(denke an die Klammer\) was der parser macht", "\", "") Dim s As String s = "aa bAAA ccab aabb" MsgBox Replace(s, "aa", "zzz") MsgBox Replace(s, "aa", "zzz", 1, -1, 1) MsgBox Replace(s, "aa", "zzz", 1, 2, 1) MsgBox Replace(s, "aa", "zzz", 1, -1, 0) MsgBox Replace(s, "aa", "zzz", 6, -1, 1) MsgBox Replace(s, "aa", "w") MsgBox Replace(s, "a", "?") MsgBox Replace(s, "a", "") ' **** This is still incorrect **** MsgBox Replace(s, "aa", "") MsgBox Replace(s, "aa", "", 1, -1, 1)
Created attachment 84311 [details] Proposed patch to fix replace ment problem and start position Current position of the searching should be calculated correctly. If start position for searching is specified (4th argument), returned string was started at the start position specified.
Created attachment 84366 [details] Document contains test case Open the attached file and push "Module1.Main" button on the document. - only "done" message is shown if no error is found. The file contains some macros for testing in Standard.Module1.
Fixed on trunk, revision 1650261.
set target
"hanya" committed SVN revision 1650261 into trunk: #i94895# fix illegal result of Replace runtime function
hanya, According to the Visual Basic replace documentation on Start: "Optional. Position within Expression that starts a substring used for replacement. The return value of Replace is a string that begins at Start, with appropriate substitutions. If omitted, 1 is assumed."[1] This means that "All characters before the start position will be removed."[2] revision 1650261 changes this behavior to include the entire string. Are you sure this is correct? [1] http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.strings.replace(v=vs.110).aspx [2] http://www.w3schools.com/vbscript/func_replace.asp
@slacka Thanks for the information. It seems the page that I checked does not contain enough information. The returned string should be starting with the start position if specified. I will commit to revert the cutting of the string at the end of the function.
"hanya" committed SVN revision 1650862 into trunk: #i94895# revert the part of revision 1650261, replaced string should be start...
Created attachment 84401 [details] Test document Fixed test case to match with start position behavior.
fixed.
*** Issue 97002 has been marked as a duplicate of this issue. ***