hello please help, here are the raw data:
str: = "fsdfsdfs {% randstr%} dfbdfbdf {% randstr%} gdfgdfg {% randstr%} fsd {% randstr%}"
how do i find and get count the number of {% randstr%} such matches?
hello please help, here are the raw data:
str: = "fsdfsdfs {% randstr%} dfbdfbdf {% randstr%} gdfgdfg {% randstr%} fsd {% randstr%}"
how do i find and get count the number of {% randstr%} such matches?
but how can I extract data from brackets right away, I need:
-to count how many elements are found
I think you can use strings.Count.
count := strings.Count( str, “{% randstr%}”)
ок, and how extract data inside {% …%} ?))
You need to find the token ({%…%} using any of Index function and then take its content. Something like
len := len(token)
for pos := strings.Index(str, token); pos != -1 ; pos = strings.Index(str, token) {
item := strings.TrimSpace(str[pos:pos+len]))
str = strings.TrimSpace(str[pos+len:])
fmt.Println(item)
}
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.