jsctechy
asked on
how to read through strings? (really easy this is like Programing 101)
i feel dumb =/
how do i ge the the first character and the last whole part of the following string using Visual Basic 05
Missipi River?
it should return something like MRIVER
easy right?
how do i ge the the first character and the last whole part of the following string using Visual Basic 05
Missipi River?
it should return something like MRIVER
easy right?
Hello,
Here is a sample code:
'========================= ========== ========== ========== ========== ==
Private Sub Command1_Click()
Dim str As String
Dim result As String
Dim lastWholePart As String
str = "Missipi River"
lastWholePart = Mid(str, InStr(1, str, " ") + 1)
result = Left(str, 1) & lastWholePart
result = UCase(result) ' in upper case
End Sub
'========================= ========== ========== ========== ========== ==
Thanks
-FA
Here is a sample code:
'=========================
Private Sub Command1_Click()
Dim str As String
Dim result As String
Dim lastWholePart As String
str = "Missipi River"
lastWholePart = Mid(str, InStr(1, str, " ") + 1)
result = Left(str, 1) & lastWholePart
result = UCase(result) ' in upper case
End Sub
'=========================
Thanks
-FA
Hi,
p = Len(strText)
Do While Mid$(strText, p, 1) <> " "
p = p - 1
Loop
so p = instr(1, strText, " ")+1
-FA
p = Len(strText)
Do While Mid$(strText, p, 1) <> " "
p = p - 1
Loop
so p = instr(1, strText, " ")+1
-FA
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Another one...
Option Explicit
Private Sub Command1_Click()
Debug.Print Abbreviate("John")
Debug.Print Abbreviate("John Goode")
Debug.Print Abbreviate("Johnny B. Goode")
Debug.Print Abbreviate("John Jacob Alexander Goode")
End Sub
Private Function Abbreviate(ByVal strIn As String) As String
Dim parts() As String
parts = Split(strIn, " ")
If UBound(parts) = 0 Then
Abbreviate = UCase(strIn)
Else
Abbreviate = UCase(Left(parts(0), 1) & Mid(parts(UBound(parts)), 1))
End If
End Function
Option Explicit
Private Sub Command1_Click()
Debug.Print Abbreviate("John")
Debug.Print Abbreviate("John Goode")
Debug.Print Abbreviate("Johnny B. Goode")
Debug.Print Abbreviate("John Jacob Alexander Goode")
End Sub
Private Function Abbreviate(ByVal strIn As String) As String
Dim parts() As String
parts = Split(strIn, " ")
If UBound(parts) = 0 Then
Abbreviate = UCase(strIn)
Else
Abbreviate = UCase(Left(parts(0), 1) & Mid(parts(UBound(parts)), 1))
End If
End Function
That's surprising. I thought that InstrRev was absent from VB5, being introduced in VB6 with the batch of other useful string functions such as Split, Join and Replace.
Function Init1AndSurnameVB5(strText
Dim p As Integer
p = Len(strText)
Do While Mid$(strText, p, 1) <> " "
p = p - 1
Loop
Init1AndSurnameVB5 = UCase$(Left$(strText, 1) & Mid$(strText, p + 1))
End Function