FAQ

On Sat, Mar 26, 2016 at 11:12 AM, Thomas Kaufmann wrote:
here is my code:

source is html-code (from GetHtml()). This works fine. But the second
Index()-call gets a smaller value then poss. Why?


func FetchMail(url string) {
25
26 mailto := "mailto:"
27 source := GetHtml(url)
28
29 poss := strings.Index(source, mailto)
30 pose := strings.Index(source[poss + len(mailto):], "\"")
31
32 fmt.Println(poss, " ", pose )
33 //s := source[poss + len(mailto):]
34
35
36 //FetchMail(url)
37 }
Indexing into source[poss + len(mailto):] gives you an index into that
substring. That is, if character source[poss + len(mailto)] == `"`,
then the result of the `strings.Index` call will be `0`. If you want
to use that result as an index into the original string, you need to
add poss + len(mailto) yourself.

Ian

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 2 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 27, '16 at 7:56p
activeMar 27, '16 at 8:31p
posts2
users2
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase