Issue 94895

Summary: BASIC-Function replace
Product: General Reporter: hawe <hawe>
Component: scriptingAssignee: ab
Status: RESOLVED FIXED QA Contact:
Severity: Trivial    
Priority: P3 CC: hanya.runo, issues, kschenk, lukebenes, marcelly.bernard, vlad
Version: OOo 3.0 RC3   
Target Milestone: 4.2.0   
Hardware: All   
OS: All   
Issue Type: DEFECT Latest Confirmation in: ---
Developer Difficulty: ---
Description Flags
Proposed patch to fix replace ment problem and start position
Document contains test case
Test document none

Description hawe 2008-10-12 13:39:00 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", "\", "")


und (denke an die Klammer\ was der parser macht

Gruß HW
Comment 1 ab 2008-11-13 10:31:17 UTC
Comment 2 bmarcelly 2011-04-07 07:15:49 UTC
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)
Comment 3 hanya 2014-12-24 04:10:38 UTC
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.
Comment 4 hanya 2015-01-02 16:19:29 UTC
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.
Comment 5 hanya 2015-01-08 15:50:20 UTC
Fixed on trunk, revision 1650261.
Comment 6 hanya 2015-01-08 15:50:57 UTC
set target
Comment 7 SVN Robot 2015-01-09 08:50:20 UTC
"hanya" committed SVN revision 1650261 into trunk:
#i94895# fix illegal result of Replace runtime function
Comment 8 slacka 2015-01-10 19:19:31 UTC

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?


Comment 9 hanya 2015-01-11 02:44:15 UTC
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.
Comment 10 SVN Robot 2015-01-11 02:53:27 UTC
"hanya" committed SVN revision 1650862 into trunk:
#i94895# revert the part of revision 1650261, replaced string should be start...
Comment 11 hanya 2015-01-11 03:15:15 UTC
Created attachment 84401 [details]
Test document

Fixed test case to match with start position behavior.
Comment 12 hanya 2015-01-11 03:20:06 UTC
Comment 13 damjan 2016-04-19 01:17:50 UTC
*** Issue 97002 has been marked as a duplicate of this issue. ***