String Library

I created a LotusScript library based on ANSI C's string library. Simple to setup:
1. Create new script library
2. Name it strlib
3. Copy and paste code into it
4. Save
5. Any where you want to use it in Lotus Script, in your Options add:
Use "strlib"

Simple to Use:
For conditional functions like strcasecmp,isalnum,isupper,etc:
if(isalnum("robert-reese")) then
' Is asalnum
else
' is not
end if
[This example was false]

for string returned functions like strstr,strcasestr,first_char:
x = strstr("abcdefg","c")
[this example x would = "cdefg"]

Any questions can be sent to redline@thereeses.net

Hope this helps.
--Rob
'strlib:

'/**********************************************
' * strlib - String Library based on ANSI C
' * Writen by Robert Reese aka Redline
' ***********************************************
' Distribute freely as long as original author
' is alway credited.
' ************************************************/
Option Public

Function isalpha(chunk As String) As Integer
' Check to see if a string is only alpha characters
Dim llow As Long, lhigh As Long
Dim ulow As Long, uhigh As Long
Dim test As Long
Dim x As Integer
Dim bit As String
isalpha = False
' Determine Unicode numeric character codes
' I doubt these would ever change.. but just to be platform and language safe.
llow& = Uni("a")
lhigh& = Uni("z")
ulow& = Uni("A")
uhigh& = Uni("Z")
'Loop thru each character to check if it's (a-z) or (A-Z)
For x% = 1 To Len(chunk$)
bit$ = Right(Left(chunk$,x%),1)
test& = Uni(bit$)
If Not( (test& >= llow& And test& <= lhigh) Or (test& >= ulow& And test& <= uhigh) ) Then
Exit Function
End If
Next
isalpha = True
End Function
Function first_char(chunk As String) As String
' Return the first character of a string
first_char = Left(chunk$,1)
End Function
Function isalnum(chunk As String) As Integer
' Check to see if a string is alphanumeric
Dim llow As Long, lhigh As Long
Dim ulow As Long, uhigh As Long
Dim nlow As Long, nhigh As Long
Dim test As Long
Dim x As Integer
Dim bit As String
isalnum = False
' Determine Unicode numeric character codes
' I doubt these would ever change.. but just to be platform and language safe.
llow& = Uni("a")
lhigh& = Uni("z")
ulow& = Uni("A")
uhigh& = Uni("Z")
nlow = Uni("0")
nhigh = Uni("9")
'Loop thru each character to check if it's (a-z) or (A-Z) or (0-9)
For x% = 1 To Len(chunk$)
bit$ = Right(Left(chunk$,x%),1)
test& = Uni(bit$)
If Not( (test& >= llow& And test& <= lhigh) Or (test& >= ulow& And test& <= uhigh) Or (test& >= nlow& And test& <= nhigh) )Then
Exit Function
End If
Next
isalnum = True
End Function
Function islower(chunk As String) As Integer
' Check to see if a string is lower case
Dim llow As Long, lhigh As Long
Dim test As Long
Dim x As Integer
Dim bit As String
islower = False
' Determine Unicode numeric character codes
' I doubt these would ever change.. but just to be platform and language safe.
llow& = Uni("a")
lhigh& = Uni("z")
'Loop thru each character to check if it's (a-z)
For x% = 1 To Len(chunk$)
bit$ = Right(Left(chunk$,x%),1)
test& = Uni(bit$)
If Not( (test& >= llow& And test& <= lhigh)) Then
Exit Function
End If
Next
islower = True
End Function
Function isspace(chunk As String) As Integer
If chunk = " " Then
isspace = True
Else
isspace = False
End If
End Function
Function isupper(chunk As String) As Integer
' Check to see if a string is upper case
Dim ulow As Long, uhigh As Long
Dim test As Long
Dim x As Integer
Dim bit As String
isupper = False
' Determine Unicode numeric character codes
' I doubt these would ever change.. but just to be platform and language safe.
ulow& = Uni("A")
uhigh& = Uni("Z")
'Loop thru each character to check if it's (A-Z)
For x% = 1 To Len(chunk$)
bit$ = Right(Left(chunk$,x%),1)
test& = Uni(bit$)
If Not((test& >= ulow& And test& <= uhigh) ) Then
Exit Function
End If
Next
isupper = True
End Function
Function strstr(chunk,sval) As String
' returns a subset of chunk starting at sval
Dim pos As Integer
strchr = ""
If (sval = "" Or chunk = "") Then Exit Function
pos% = Instr(chunk,sval)
If(pos% = 0) Then Exit Function
pos% = (Len(chunk) - pos) + 1
strchr = Right(chunk,pos%)
End Function
Function strcasecmp(str1,str2) As Integer
'compares two strings regardless of case
Dim x As Integer
Dim bit1 As String, bit2 As String
strcasecmp = False
If Len(str1) <> Len(str2) Then Exit Function
For x% = 1 To Len(str1)
bit1$ = Right(Left(str1,x%),1)
bit2$ = Right(Left(str2,x%),1)
If(Lcase(bit1$) <> Lcase(bit2$)) Then Exit Function
Next
strcasecmp = True
End Function
Function strcasestr(str1,str2) As String
'returns a subset of str1 startining at str2 regarless of case
Dim pos As Integer
strcasestr = ""
If (str1 = "" Or str2 = "") Then Exit Function
pos% = Instr(Lcase(str1),Lcase(str2))
If(pos% = 0) Then Exit Function
pos% = (Len(str1) - pos) + 1
strchr = Right(str1,pos%)
End Function

This was first published in November 2000

Dig deeper on Domino Resources - Part 4

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close