SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Library Return Values

 
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite View previous topic
View next topic
Library Return Values
Author Message
Joshua Youngblood



Joined: 14 Apr 2006
Posts: 82
Country: United States

Post Library Return Values Reply with quote
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:

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:
Code:

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 View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7949

Post Reply with quote
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,

Code:
Concat("$", data, date)
Return data


in the calling code
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 View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
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


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.