Extract Sentences from a String in Go

Cloudmersive
1 min readMar 14, 2022

--

Pull individual sentences from a string and return those sentences in a list with a sentence count. Simple as that. Ready-to-run code examples in Go from our Cloudmersive API Console page are included below for your convenience — copy and paste, include your Cloudmersive API key, and you’re all set to go:

package mainimport (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {url := "https://api.cloudmersive.com/nlp-v2/segmentation/sentences"
method := "POST"
payload := strings.NewReader("InputString=%3Cstring%3E")client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Apikey", "YOUR-API-KEY-HERE")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

Don’t have an API key yet? Head to our website (www.cloudmersive.com) and create an account to receive your key. There are several account options, including a free-tier account with no financial commitments & a limit of 800 API calls per month.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet