• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

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?
0
jsctechy
Asked:
jsctechy
1 Solution
 
GrahamSkanCommented:
Not too difficult:

Function Init1AndSurnameVB5(strText As String) As String
    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

0
 
Farzad AkbarnejadCommented:
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
0
 
Farzad AkbarnejadCommented:
Hi,

    p = Len(strText)
    Do While Mid$(strText, p, 1) <> " "
        p = p - 1
    Loop
   

so p = instr(1, strText, " ")+1

-FA  

     
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
BrianGEFF719Commented:
You can do it in one line:

Dim myStr As String
dim newStr as String
myStr = "Missipi River"
newStr =  UCase(Left(myStr, 1) & Right(myStr, Len(myStr) - InStrRev(myStr, " ")))


msgbox newStr


Good Luck :)
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
0
 
GrahamSkanCommented:
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now