Strip out text

Geoff Codd

Registered User.
Local time
Today, 20:29
Joined
Mar 6, 2002
Messages
190
Hi there,

I have several amounts of data which lokks like this

Brazilië (Sao Paulo)

What I need to do is strip out anything in brackets so I am left with

Brazilië

Any ideas?

Thanks in advance
Geoff
 
The following should solve your problem.

Code:
Public Function StringBefore(strOrig As String, strSearch As String)
' Extracts the string that occurs bebefore the search string specified

  Dim intSearchPos As Integer
  Dim strProc As String
  
  ' find position of first occurence of strStart
  intSearchPos = InStr(1, strOrig, strSearch)
  
  strProc = left(strOrig, intSearchPos - 1)
  
  StringBefore = strProc

End Function

Public Function StringBetween(strOrig As String, strStart As String, strEnd As String)
' Extracts the string that occurs between the start and end search strings specified

  Dim intStartPos As Integer, intEndPos As Integer
  Dim strProc As String
  
  ' find position of first occurence of strStart
  intStartPos = InStr(1, strOrig, strStart)
  ' find position of first occurence of strEnd after strStart
  intEndPos = InStr(intStartPos + 1, strOrig, strEnd)
  
  strProc = Mid(strOrig, intStartPos + 1, intEndPos - intStartPos - 1)
  
  StringBetween = strProc

End Function

Example:
StringBefore("Brazilië (Sao Paulo)","(") = "Brazilië "
StringBetween("Brazilië (Sao Paulo)","(",")") = "Sau Paulo"
 

Users who are viewing this thread

Back
Top Bottom