Skip to content

Instantly share code, notes, and snippets.

@davebrny
Last active January 24, 2017 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davebrny/a440ce36d11364d2f7cfc6d89d2f3f63 to your computer and use it in GitHub Desktop.
Save davebrny/a440ce36d11364d2f7cfc6d89d2f3f63 to your computer and use it in GitHub Desktop.
(autohotkey) - split between two characters/words/sentences
between(string, left, right) {
if (strLen(left) > 1) ;# if its a word or sentence
{
string := strReplace(string, left, "¢") ; replace with symbol
left := "¢" ; set new deliminator
}
if (strLen(right) > 1)
{
string := strReplace(string, right, "¢")
right := "¢"
}
stringSplit, split, string, % left ;# if its a single character
stringSplit, split, split2, % right
return split1
}
/*
[script info]
version = 0.2
description = split between two characters/words/sentences
author = davebrny
source = https://gist.github.com/davebrny/a440ce36d11364d2f7cfc6d89d2f3f63
*/
@davebrny
Copy link
Author

string := "version (0.1)"
result := between(string, "(", ")")
msgBox, "%result%"    ; returns "0.1"

string := "error at line 42 in file"
result := between(string, "error at line", "in file")
msgBox, "%result%"    ; returns "42"

string := "error at line 42* in file"  
result := between(string, "error at ", "*")
msgBox, "%result%"    ; returns "line 42"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment