Advertisement
Stevoisiak

Function for splitting delimited strings in AutoHotkey

Aug 23rd, 2017
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Based on Oleg's answer to "How can I split tab-delimited strings in Autohotkey?"
  2. ; https://stackoverflow.com/q/45620437/3357935
  3.  
  4. ; Split tab-delimited string to a 2D array
  5. SplitToArray(unsplitString) {
  6.    lines := StrSplit(unsplitString, "`n")
  7.    columns := []
  8.    for index, value in lines
  9.       columns.Insert(StrSplit(value, "`t"))
  10.    Return columns
  11. }
  12.  
  13. ; Split arbitrary-delimited string to a 2D array
  14. SplitToArray(unsplitString, separator:="`t") {
  15.    lines := StrSplit(unsplitString, "`n")
  16.    columns := []
  17.    for index, value in lines
  18.       columns.Insert(StrSplit(value, separator))  ; defaults to `t
  19.    Return columns
  20. }
  21.  
  22. ; Examples
  23. columns := SplitToArray(clipboard)
  24. MsgBox % columns[1][1] ; Unit
  25. MsgBox % columns[1][2] ; Dept_ID
  26. MsgBox % columns[1][3] ; Name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement