Issue 94895 - BASIC-Function replace
Summary: BASIC-Function replace
Status: RESOLVED FIXED
Alias: None
Product: General
Classification: Code
Component: scripting (show other issues)
Version: OOo 3.0 RC3
Hardware: All All
: P3 Trivial (vote)
Target Milestone: 4.2.0
Assignee: ab
QA Contact:
URL:
Keywords:
: 97002 (view as issue list)
Depends on:
Blocks:
 
Reported: 2008-10-12 13:39 UTC by hawe
Modified: 2016-04-19 01:17 UTC (History)
6 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
Proposed patch to fix replace ment problem and start position (641 bytes, patch)
2014-12-24 04:10 UTC, hanya
no flags Details | Diff
Document contains test case (12.38 KB, application/vnd.oasis.opendocument.text)
2015-01-02 16:19 UTC, hanya
no flags Details
Test document (12.49 KB, application/vnd.oasis.opendocument.text)
2015-01-11 03:15 UTC, hanya
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
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", "\", "")

result

und (denke an die Klammer\ was der parser macht

Gruß HW
Comment 1 ab 2008-11-13 10:31:17 UTC
STARTED, 3.x
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
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
Comment 9 hanya 2015-01-11 02:44:15 UTC
@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.
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
fixed.
Comment 13 damjan 2016-04-19 01:17:50 UTC
*** Issue 97002 has been marked as a duplicate of this issue. ***