Advertisement
4_2005-2006 String Manipulation #156917

Extract String Function

This code will search a string for a given starting point(strFind) and a given end point(strSentinel) and return all the text in between. You can also add to the length of the start point if you don't want to include a number of unknown characters in the result

AI

ИИ-обзор: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Исходный код
original-source
Function ExtractString(ByVal strText As String, _
               strFind As String, _
               intAddToLen As Integer, _
               strSentinel As String, _
               TrapErrors As Boolean, _
               intLength As Integer) As String
               
  Dim SStart     As Integer
  Dim SEnd      As Integer
   
  SStart = InStr(1, strText, strFind) + Len(strFind) + intAddToLen
  If SStart <= Len(strFind) And TrapErrors = True Then
    MsgBox """" & strFind & """ not found!", vbCritical, "Error"
    Exit Function
  End If
  
  SEnd = InStr(SStart, strText, strSentinel)
  If SEnd <= Len(strFind) And TrapErrors = True Then
    MsgBox "Sentinel value """ & strSentinel & """ not found!", vbCritical, "Error"
    Exit Function
  End If
  
  If intLength > 0 Then
    ExtractString = Mid(strText, SStart, intLength)
  Else
    ExtractString = Mid(strText, SStart, (SEnd - SStart))
  End If
End Function
Оригинальные комментарии (3)
Восстановлено из Wayback Machine