hcl-bot
November 13, 2007, 10:06am
1
Hi all,
Seemds simple enough, but I looked at the posting on the site, yet I could not find a way to do this using Lotus script.
I am trying to count the munber of “~” in a string using script…
test = “ABC~DFG~HIJ”
if Number of “~” test > 3 then
do this
else do that
end if
thanks
hcl-bot
November 13, 2007, 10:38am
2
Subject: Counting number of special characters in a string
Sub Click(Source As Button)
test1$ = "ABC~DFG~HIJ"
cnt1% = Len(test1$)
test2$ = Replace(test1$, "~", "")
cnt2% = Len(test2$)
tildecount% = cnt1% - cnt2%
Msgbox "there are " & Cstr(tildecount%) & " tildes"
End Sub
hcl-bot
November 13, 2007, 10:55am
3
Subject: RE: Counting number of special characters in a string
Thanks all for the help it is working… now I am working on the second part of my code…
Regardless of the number of “~” in the code I will always need the first and second part of the string.
So if the string is like “ABC~DFG~RDT~RTY” I would always want to get “ABC~DFG”
paul,
hcl-bot
November 13, 2007, 10:56am
4
hcl-bot
November 13, 2007, 11:17am
5
Subject: RE: Counting number of special characters in a string
yes you are right… but I still need to create this using lotus script…
hcl-bot
November 13, 2007, 11:22am
6
Subject: RE: Counting number of special characters in a string
Sub Click(Source As Button) Dim s As String
Dim v As Variant
Dim c As Integer
Dim x As String
Dim t As String
s = "ABC~DEF~GHI~HJK"
Gosub DoSplit
s = "ABC~"
Gosub DoSplit
s = "ABC"
Gosub DoSplit
s = "ABC~~DEF~GHI~HJK"
Gosub DoSplit
Exit Sub
DoSplit:
x = ""
t = "NFG"
v = Split(s, "~")
c = Ubound(v)
If c > 0 Then
x = v(0) & "~" & v(1)
t = "OK"
End If
Msgbox x, , t
Return
End Sub
hcl-bot
November 13, 2007, 2:09pm
7
Subject: RE: Counting number of special characters in a string
thanks for the help all of you.
hcl-bot
November 13, 2007, 10:15am
8
Subject: Counting number of special characters in a string
You could define a variant variable, use the split function then use ubound-1 to find how many ~ there are.
something like:
Dim ret As Variant
dim teststr as string
dim chrctr as integer
test = “ABC~DFG~HIJ”
ret = split(test, “~”)
chrctr = ubound(ret)-1
if chrctr > 3 then do this else do that end if
hcl-bot
November 13, 2007, 10:21am
9
Subject: RE: Counting number of special characters in a string
check chrctr = ubound(ret)-1. Might not need to delete 1 from the result because the index will start at 0
hcl-bot
November 13, 2007, 10:12am
10
Subject: Counting number of special characters in a string
From Designer Help:
@Explode ( string ; separators ; includeEmpties )
x := @Explode (“ABC~DFG~HIJ”; “~”; @True );
NumberOfSeparatorOccurences := @Elements (x)-1;