Lotus Notes / Domino Sonstiges > Projekt Bereich

@Formula-Befehle in Lotus Script abbilden

<< < (2/21) > >>

TMC:
@Count

--- Code: ---Function atCount(s$, k$) As Long
   Dim p&, r&
   p = 1
   atCount = 0
   While p>0
      r = Instr(p, s$, k$)
      If r>0 Then
         atCount = atCount + 1
         p  =  r + Len(k$)
      Else
         p = 0
      End If
   Wend
End Function
--- Ende Code ---

TMC:
@Explode

--- Code: ---Function atExplode(Byval s$, Byval div$) As Variant
   Redim result(0 To 0) As String
   Dim i%, pos&, oldpos&, skip&
   oldpos = 1
   skip = Len(div)
   pos = Instr(s, div)
   Do Until pos = 0
      Redim Preserve result(0 To i+1)
      result(i) = Mid$(s, oldpos, pos-oldpos)
      i = i + 1
      oldpos = pos + skip
      pos = Instr(oldpos, s, div)
   Loop
   result(i) = Mid$(s, oldpos)
   atExplode = result
End Function
--- Ende Code ---

TMC:
@Implode


--- Code: ---Function atImplode(s, div As String) As String
   If Isarray(s) Then
      Dim i%
      atImplode = s(Lbound(s))
      For i = Lbound(s)+1 To Ubound(s)
         atImplode = atImplode & div & s(i)
      Next
   Else
      atImplode = Cstr(s)
   End If
End Function
--- Ende Code ---

@ReplaceSubstring


--- Code: ---Function atReplaceSubstring(source As Variant, repl As Variant, replacewith As Variant) As Variant
' Written 24 Sept 1996 by Andre Guirard.
   Dim tTo As Variant, tFrom As Variant
   Dim i&, j&
   
' If the search string and replacement are not arrays, make them one element arrays; this makes the
' subsequent code simpler.
   If Isarray(repl) Then
      tFrom = repl
   Else
      tFrom = SingleElementArray(repl)
   End If
   If Isarray(replacewith) Then
      tTo = replacewith
   Else
      tTo = SingleElementArray(replacewith)
   End If
   
' If the main input is an array, recursively process each element and return the results as an array.
   If Isarray(source) Then
      Redim result(Lbound(source) To Ubound(source)) As Variant
      For i = Lbound(source) To Ubound(source)
         result(i) = atReplaceSubstring(source(i), tFrom, tTo)
      Next
      atReplaceSubstring = result
   Else
      Dim res$, src$
      src$ = source
      For i = 1 To Len(src$)
' Scan the list of search strings to see whether any of them is present at position i in the source string.
         For j = Lbound(tFrom) To Ubound(tFrom)
            If tFrom(j) = Mid$(src$, i, Len(tFrom(j))) Then
               Exit For
            End If
         Next
' If a match was found, replace it in the output with the corresponding "replacewith" entry.
         If j <= Ubound(tFrom) Then
            res$ = res$ + tTo(min(Ubound(tTo), j))
            i = i + max(0, Len(tFrom(j)) - 1)
  ' shift the input pointer past the end of the matching string so we don't match another string in the middle of it.
         Else
' Otherwise, copy over the one character at position i.
            res$ = res$ + Mid$(src$, i, 1)
         End If
      Next
      atReplaceSubstring = res$
   End If
End Function
--- Ende Code ---

Semeaphoros:
Well, in R5 und nochmal in ND6 sind eine ganze Reihe solcher Sachen in Script aufgetaucht, zum Bleistift:

Removes duplicate elements from an Array.
Syntax
ArrayUnique(sourceArray [,compMethod ])



Replaces specific words or phrases in a string with new words or phrases that you specify.
Syntax
Replace(sourceArray as Variant, findArray as Variant, replacementArray as Variant[, start as Integer[, count as Integer[, compMethod as Integer]]]) as Variant



Die ND6-Designer-Hilfe hat häufig (leider nicht immer) eine Cross-Language-Section, so dass man diese Aequivalente findet.

koehlerbv:
TMC, der Rückgabewert ist genau nicht skalar, sondern ein Array (ein- oder mehrdimensional).

Dim v As Variant
v = Evaluate ({@Left ("Das ist ein Test"; 16)})

Msgbox v ergibt nun einen Fehler, es muss ja
Msgbox v (0) heissen.

@TMC:
ReplaceSubstring wie von Dir angegeben ist sicher die im Web häufigst verbreitete Variante, entspricht aber keineswegs dem @ReplaceSubstring - denn dieses verarbeitet auch Arrays und nicht nur Strings. Hier im Forum gibt es m.E. schon eine "richtige Umsetzung".

Die Idee einer wirklich sicheren (!) Umsetzung cooler @functions in einer Art wie Deine "Schlaufen"-Doku von AtNotes hat aber was !
Dies sollte aber unter keinen Umständen auf Nachbildungen von @functions begrenzt sein, sondern um immer wieder benötigte Funktionen wie "IsValueEmpty" oder "CompareValues" oder oder ergänzt werden !

Ich wäre auf jeden Fall mit dabei ;-)

Bernhard

Navigation

[0] Themen-Index

[#] Nächste Seite

[*] Vorherige Sete

Zur normalen Ansicht wechseln