Question:
How can I inverse the current case of a string in VB6 eg Hello:hELLO?
redrose
2006-03-09 23:47:05 UTC
I tried using the StrConv function but it could only convert in lower, upper or proper case.
Two answers:
Flavio
2006-03-10 07:10:42 UTC
Copy this and paste it into your code:



Original = "Hello"

Lower = LCase(Original)

Upper = UCase(Original)

Reverse = ""

For i = 1 To Len(Original)

If Mid(Original, i, 1) < Mid(Lower, i, 1) Then

Reverse = Reverse + Mid(Lower, i, 1)

Else

Reverse = Reverse + Mid(Upper, i, 1)

End If

Next
kirun
2006-03-10 00:38:13 UTC
I've used VB exactly once, but I presume there will be suitable language features for this.



You'd write a function that looked at each character of the string individually - I presume there would be either array access to the string, or an equivalent to a .charAt(n) function for this purpose.



A simple way would be to look at the character code for the string (e.g. a=97, A=65), and based on its range, do some simple maths on it. This, however, unless the function gets complicated, won't do accents.



A sneaky trick would be to create two copies of the string, and uppercase one, and a lowercase one. Then, you could run through the string, compare each character to the equivalent in the two copies, and then use the different one.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...