# UPPER vs lower Count

I am going to make some assumptions since you didn’t 100% define the environment
one being that a binary compare returns 0 or 1

``````dim bucket(1) as Integer
S="AStringWithUpperAndLowerCaseCharacters"
for i=1 to S.Len
bucket(ABS((ASC(mid(s,i,1)>ASC("Z")))+=1
next i
``````

pseudo code just to illustrate my idea

not sure of the context ? whose blog ? link to the post this is in response to ?

1 Like

UH YOURS???

https://www.great-white-software.com/blog/2020/03/06/programming-thought-experiments/

since there is no way to post comments to your blog… or if there is I sure couldn’t find it

@DaveS If you click the blog title on @npalardy site then it’ll take you to a separate page with the blog post. The comments are available there.

Yup… uh… nope… you can enter a comment… but they then just seem to vanish…
oh well… no worries

Dim LowerChars, UpperChars, theByte as integer
Dim CharArr() as String = Split(“123abc123ABCD”,””)

For each theChar as String in CharArr
theByte =Asc(theChar)
LowerChars = LowerChars + (thebyte\97) – (thebyte\123)
UpperChars = UpperChars + (thebyte\65) – (theByte\91)
Next

1 Like

The same code not using “magic numbers”:

Dim LowerChars, UpperChars, theByte as integer
Dim CharArr() as String = Split(“123abc123ABCD|”,"")

Dim UpperCaseStart as Integer = Asc(“A”)
Dim UpperCaseEnd as Integer= Asc(“Z”) + 1

Dim LowerCaseStart as Integer = Asc(“a”)
Dim LowerCaseEnd as Integer = Asc(“z”) + 1

For each theChar as String in CharArr
theByte =Asc(theChar)
LowerChars = LowerChars + (thebyte\LowerCaseStart) - (thebyte\LowerCaseEnd)
UpperChars = UpperChars + (thebyte\UpperCaseStart) - (theByte\UpperCaseEnd)
Next

1 Like

initial comment has to be approved by the moderator
and I was away all day so …

Too often life is just write-only, Dave.

2 Likes