Split a string and get certain character

dastr

Registered User.
Local time
Today, 09:31
Joined
Apr 1, 2012
Messages
43
Hi all,

I have the following text string 30.CHARACTER.XXX and I would like to have only the CHARACTER, the text in between dots (.) dows anyone know how I may split it up?

Thanks
 
You have to use the combination of Mid() and InStr() might also need InStrRev(), to get what you are trying to achieve..

Or also use Split(), that will return a String array..
 
Last edited:
You could use this.

Code:
Public Function getStringBetweenDots(Byval theString as variant)
  Dim lngDot as Long

  theString = theString & vbNullString ' Deals with empty strings

  lngDot = Instr(theString, ".")
  If lngDot > 0 Then theString = Mid(theString, lngDot +1) ' Gets rid of stuff before 1st Dot

  lngDot = Instr(theString, ".")
  If lngDot > 0 Then theString = Mid(theString, 1 , lngDot -1)  ' Gets rid of stuff after 2nd Dot

  getStringBetweenDots = theString
End Function
 
This is how you use Split()
Code:
Public Function getStringBetweenDots(ByVal theString As Variant)
    Dim strArr() As String
    strArr = Split(theString, ".")
    getStringBetweenDots = strArr(1)
End Function
 

Users who are viewing this thread

Back
Top Bottom