You were on a good start with strings.Index(). The key is to move
past the pattern you searched for, assuming it was found.
Something like this should work, if `bigString` is what you are
searching over, and depending on whether "Core Count:" might be on the
first line or not:
pattern := "\nCore Count: "
if start := strings.Index(bigString, pattern); start >= 0 {
var nCores int
_, err := fmt.Sscanf(bigString[start+len(pattern):], "%d", &nCores)
if err == nil {
fmt.Println("Number of cores:", nCores)
}
}
As you can see, the regular expression-based solution suggested by
others leads to less code. This input string is so short that CPU
usage will be negligible for most purposes, outweighed by graceful
error handling and code maintenance concerns.
Best regards,
Michael