Skip to content

Instantly share code, notes, and snippets.

@lisp-ceo
Created October 15, 2016 01:06
Show Gist options
  • Save lisp-ceo/1735d94d185edc2c4b8207414abdcd13 to your computer and use it in GitHub Desktop.
Save lisp-ceo/1735d94d185edc2c4b8207414abdcd13 to your computer and use it in GitHub Desktop.
func expand(s string, f func(string) string) string {
if len(s) < len(FOO) {
return s
}
for i := strings.Index(s, FOO); i != -1; i = strings.Index(s, FOO){
t := s[:i]
t = t + f(s[i+1:i+len(FOO)])
t = t + s[i+len(FOO):]
s = t
}
return s
}
@lisp-ceo
Copy link
Author

What I want is a C-style while loop but when I run it as for i := strings.Index(s, FOO) {} it gives a compilation error saying the function is used as a value.

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