 |
SoftTree Technologies
Technical Support Forums
|
|
Author |
Message |
Joshua Youngblood
Joined: 14 Apr 2006 Posts: 82 Country: United States |
|
Library Return Values |
|
We are using 3.5.2.
We have written a library called replaceall. It is used to replace all particular findings of a string within a given string.
Its parameters are:
1. data (string) - This is the string whose found substrings will be replaced
2. find_str (string) - This is the substring that will be replaced
3. replace_str (string) - This is the string that will replace all occurences of find_str.
The library returns a string.
Here's the library's code:
 |
 |
Dim find_len, number
Dim find_pos, number
Dim replace_len, number
Length find_str, find_len
Length replace_str, replace_len
Pos data, find_str, 1, find_pos
// Using a messagebox here I am able to verify that the "data" parameter is still a string. I will explain
// the error soon.
LoopWhile find_pos, END_LOOP
Replace data, find_pos, find_len, replace_str, data
Add find_pos, replace_len, find_pos
Pos data, find_str, find_pos, find_pos
END_LOOP:
// Using a messagebox here I am able to verify, again, that the "data" parameter is still a string.
Return data
|
Here's an example of replaceall being used:
 |
 |
dim myString, string, "01"
messagebox myString
// In this call to replaceall, a single-quote would get replaced with two single-quotes. Because
// "01" has no single-quotes, we should just get back "01", which is what we passed. Instead we
// get "1".
replaceall(myString, "'", "''", myString)
messagebox myString
|
Problem: When the "01" is passed back from replaceall, which should return a string, the leading zero gets removed. This is causing peculiar behavior for us because we are expecting to receive the exact same string that we passed. We are currently able to work around this, but I thought I would let you know of the behaviour because I didn't know if JAL was programmed that way on purpose or not.
|
|
Thu Dec 11, 2008 4:58 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7949
|
|
|
|
As you correctly identified this is a result of automatic data type conversion. To ensure you always return string, you can prefix it with some non digit character then drop this character later. For example, in the 'replace all' before returning the result,
 |
 |
Concat("$", data, date)
Return data |
in the calling code
 |
 |
ReplaceAll(myString, "'", "''", myString)
Mid(myString, 2, 100000, myString) |
This doesn't look very logical and requires one extra step, but it should work. Please give it a try
|
|
Thu Dec 11, 2008 6:09 pm |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|