Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.17 KB | None | 0 0
  1. ; #FUNCTION# ====================================================================================================================
  2. ; Name...........: _StringBetween
  3. ; Description ...: Returns the string between the start search string and the end search string.
  4. ; Syntax.........: _StringBetween($s_String, $s_start, $s_end[, $v_Case = -1])
  5. ; Parameters ....: $s_String       - The string to search.
  6. ;                  $s_start        - The beginning of the string to find.  Passing a blank string starts at the beginning
  7. ;                  $s_end          - The end of the string to find.  Passing a blank string searches from $s_start to end
  8. ;                  $v_Case         - Optional: Case sensitive search. Default or -1 is not Case sensitive else Case sensitive.
  9. ; Return values .: Success - A 0 based $array[0] contains the first found string.
  10. ;                  Failure - 0
  11. ;                  |@Error  - 1 = No inbetween string found.
  12. ; Author ........: SmOke_N (Thanks to Valik for helping with the new StringRegExp (?s)(?i) isssue)
  13. ; Modified.......: SmOke_N - (Re-write for speed and accuracy)
  14. ; Remarks .......: 2009/05/03 Script breaking change, removed 5th parameter
  15. ; Related .......:
  16. ; Link ..........:
  17. ; Example .......: Yes
  18. ; ===============================================================================================================================
  19. Func _StringBetween($s_String, $s_Start, $s_End, $v_Case = -1)
  20.  
  21.     ; Set case type
  22.     Local $s_case = ""
  23.     If $v_Case = Default Or $v_Case = -1 Then $s_case = "(?i)"
  24.  
  25.     ; Escape characters
  26.     Local $s_pattern_escape = "(\.|\||\*|\?|\+|\(|\)|\{|\}|\[|\]|\^|\$|\\)"
  27.     $s_Start = StringRegExpReplace($s_Start, $s_pattern_escape, "\\$1")
  28.     $s_End = StringRegExpReplace($s_End, $s_pattern_escape, "\\$1")
  29.  
  30.     ; If you want data from beginning then replace blank start with beginning of string
  31.     If $s_Start = "" Then $s_Start = "\A"
  32.  
  33.     ; If you want data from a start to an end then replace blank with end of string
  34.     If $s_End = "" Then $s_End = "\z"
  35.  
  36.     Local $a_ret = StringRegExp($s_String, "(?s)" & $s_case & $s_Start & "(.*?)" & $s_End, 3)
  37.  
  38.     If @error Then Return SetError(1, 0, 0)
  39.     Return $a_ret
  40. EndFunc   ;==>_StringBetween
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement