BlueNachid

String Array Between Function

Dec 18th, 2015
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 1.32 KB | None | 0 0
  1. #cs
  2. Simply put in ur $string, the $start where u wanna $start capturing and the $end.
  3. Like this
  4.  
  5. $string = "<h1 class='someclass'>The 'data'  i want</h1>"
  6. $start = "<h1 class='someclass'>"
  7. $end = "</h1>"
  8.  
  9. and u will recive "The 'data' i want".
  10.  
  11. You can even querry a array out of any text with this function.
  12. $string = "<h1 class='someclass'>The 'data'  i want</h1>"
  13. $start = "'"
  14. $end = "'"
  15.  
  16. If you put in this the return would be
  17.  
  18. [0] someclass
  19. [1] data
  20.  
  21. Thank you for using my work.
  22. BTW : please Test for StrInStr. If it not appears ull recive a error.
  23. #ce
  24.  
  25.  
  26. Func between($string, $start, $end, $array = 0)
  27.     If $array = 0 Then
  28.         $string = StringSplit($string, $start, 1)
  29.         If $string[0] < 2 Then Return 0
  30.         $string = $string[2]
  31.         $string = StringSplit($string, $end, 1)
  32.         If @error = 1 Then Return 0
  33.         $string = $string[1]
  34.         Return $string
  35.     Else
  36.         Local $startstring = StringSplit($string, $start, 1)
  37.         Local $nextsplitt[1]
  38.         For $i = 2 To $startstring[0] Step +1
  39.             If $i <= $startstring[0] Then
  40.                 _ArrayAdd($nextsplitt, $startstring[$i])
  41.             EndIf
  42.         Next
  43.         Local $returner[1]
  44.         For $i = 1 To UBound($nextsplitt) - 1
  45.             Local $rs = StringSplit($nextsplitt[$i], $end, 1)
  46.             _ArrayAdd($returner, $rs[1])
  47.         Next
  48.         Return $returner
  49.     EndIf
  50. ;Function by Nachid - U3C0
  51. ;schindler-it.org
  52. EndFunc   ;==>between
Advertisement