learner
12th May 2005, 09:50
Hi,

I have a string which contains 1 single quote , i would like to replace it with 2 single quotes , is there any standard function to achive this in BaaN ?

Regards

Learner

mark_h
12th May 2005, 15:56
Never tried this with a single quote, but you could do something like this:

scan.ret = string.scan(str1,"(%s'%s)",str2,str3)
newstr = str2 & "''" & str3

Not sure if this will work with a single quote, but this is the first thing that popped into my mind. You can do a search on string.scan and I believe you can find other alternatives.

NPRao
12th May 2005, 23:06
Use -

search.and.replace
void search.and.replace( ref string line(), const string srch(),
const string replace() )

desc: This function replaces all occurences of the substring "srch"
with the substring "replace" in the string line
from library - ttdllstring

mark_h
13th May 2005, 00:01
Dang - another Baan V functionality. I could not find it in ottdllstring on our system.

NPRao
13th May 2005, 00:16
Sometimes its worth the upgrade... :) ofcourse, after evaluating the ROI.

bhushanchanda
23rd April 2014, 18:19
Hi,

Quite old thread but just thought to update it.

find.and.replace() has some problems.

e.g. If we have to replace all commas (,) in tcibd001.dsca (Item Description) with length 30 char with space (" "), the function was trying to increase the length of the string which was causing Fatal Error's saying index out of range. May be if they should have provided some pre-requisites with this function. And I guess this the reason why a new function is introduced.


str.replace$()
Syntax:
function string str.replace$ (const string string$, const string oldstr$, const string newstr$)

Description

Returns a (null terminated) copy of string$ that will have all instances of oldstr$ replaced with newstr$.

As this function returns a string value that can become larger than the input string, you have to use a variable that is large enough to store the result.


Arguments
const string string$ a string

const string oldstr$ the part to replace

const string newstr$ the part to replace oldstr$ withEXAMPLE:-

string source(50)
string target(100)
string temp(10)

| 1 2 3 4 5
| pos 12345678901234567890123456789012345678901234567890
source = "the quick brown fox jumps over the lazy dog"

target = str.replace$(source, "dog", "cat")
| target now contains "the quick brown fox jumps over the lazy cat"

target = str.replace$(source, "the", "a")
| target now contains "a quick brown fox jumps over a lazy cat"

target = str.replace$(source, "o", "O")
| target now contains "the quick brOwn fOx jumps Over the lazy dOg"

target = str.replace$(source, " ", " ")
| target now contains "the quick brown fox jumps over the lazy dog"

target = str.replace$(source, "the", "")
| target now contains "quick brown fox jumps over lazy dog"

temp = str.replace$(source, "", "the")
| nothing replaced
| target now contains "the quick brown fox jumps over the lazy dog"

temp = str.replace$(source, "the", "")
| temp now contains "quick brow" as temp can contain only 10 chars

Alternatively, str.replace() can also be used. Both work pretty well.

NOTE:- TIV should be >= 1700