Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 462
  • Last Modified:

@ReplaceSubstring equivalent in LotusScript.

Hi,

I've the following code in my agent

Let Cnam = Trim$(doc.Custname(0))
Let CIAccount$ = Ucase(Cnam)                  

Set Collection = db.getView("*Counts\CBCN").getAllDocumentsByKey(CIAccount$)
If Collection.Count = 0 Then                          
     'Display MessageBox    
Else
    'Do Processing
End If      


Now In the view "*Counts\CBCN"  I've the first column as the following: @ReplaceSubstring(@UpperCase(@Trim(CustomerName)); " "; "+")
I'm replacing all spaces with +.

Now I've to do the same in CIAccount$.

Lets say if the user enters "IBM Data Services Inc" in the doc.Custname(0) field in the form
The CIAccount$ will have "IBM Data Services Inc".  I want it as IBM+Data+Services+Inc.

If I do not replace spaces with + here the search will not work.

Now you can tell me that just change the column formula to @UpperCase(@Trim(CustomerName)). But that is not what I want to do here becuase,
Lets say if the User is entering just "AA" in the doc.Custname(0) field and in the view "*Counts\CBCN" I've "AAA - R", It is still considering as a match which is incorrect. I guess it all becuase of the spaces.

Please advise.
thanks
Kalios
0
kalios
Asked:
kalios
2 Solutions
 
RanjeetRainCommented:
Hey buddy,

I have something ready to use for you. This is from my library:




Function ReplaceString(Byval Src As String, Byval Str1 As String, Byval Str2 As String) As String
      If  Src = "" Or Src = Null  Or  Str1 = "" Or Str1 = Null  Then
            ReplaceString = Src
            Exit Function
      End If
      
      Dim beginAt As Integer
      Dim foundAt As Integer
      Dim srcLen As Integer
      Dim repLen As Integer
      
      srcLen = Len(Src)
      repLen = Len(Str1)
      beginAt = 1
      foundAt = -1
      
      Do While foundAt <> 0
            'Msgbox "calling Instr with " & beginAt & ":" & src & ":" & str1
            foundAt = Instr(beginAt, Src, Str1, 5)
            If foundAt > 0 Then
                  Mid (Src, foundAt, repLen) = Str2
            End If
            beginAt = FoundAt                  
      Loop      
      
      ReplaceString = Src
End Function



Good luck!
0
 
HemanthaKumarCommented:
getAllDocumentsByKey(CIAccount$,TRUE)... the additional parameter specify exact match should be performed on the search.. This will avoid any wildcard searches

~Hemanth
0
 
kaliosAuthor Commented:
Thanks Hemanth and Ranjeet.

I've used Hemanths. It works great.

Kalios
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now