本文整理汇总了Golang中strings.SplitAfterN函数的典型用法代码示例。如果您正苦于以下问题:Golang SplitAfterN函数的具体用法?Golang SplitAfterN怎么用?Golang SplitAfterN使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SplitAfterN函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Get
func (self *ProcState) Get(pid int) error {
contents, err := readProcFile(pid, "stat")
if err != nil {
return err
}
headerAndStats := strings.SplitAfterN(string(contents), ")", 2)
pidAndName := headerAndStats[0]
fields := strings.Fields(headerAndStats[1])
name := strings.SplitAfterN(pidAndName, " ", 2)[1]
if name[0] == '(' && name[len(name)-1] == ')' {
self.Name = name[1 : len(name)-1] // strip ()'s
} else {
return errors.New(fmt.Sprintf("Malformed process stats for pid %d", pid))
}
self.State = RunState(fields[0][0])
self.Ppid, _ = strconv.Atoi(fields[1])
self.Tty, _ = strconv.Atoi(fields[4])
self.Priority, _ = strconv.Atoi(fields[15])
self.Nice, _ = strconv.Atoi(fields[16])
self.Processor, _ = strconv.Atoi(fields[36])
return nil
}
示例2: getcityname
func getcityname(city string) string {
if strings.Contains(city, "县") {
citys = strings.SplitAfterN(city, "市", 2)[1]
}
if strings.Contains(city, "市") {
if strings.Count(city, "市") >= 2 {
citys = strings.SplitAfterN(city, "市", 2)[1]
} else {
citys = strings.SplitAfterN(city, "省", 2)[1]
}
}
if strings.Contains(city, "区") {
if strings.Count(city, "区") >= 2 {
citys = strings.SplitAfterN(city, "区", 2)[1]
} else {
if strings.Contains(city, "特别行政区") {
citys, _ = SubstringIndex(city, "特别行政区")
}
if strings.Contains(city, "市") {
citys = strings.SplitAfterN(city, "市", 2)[1]
}
}
}
return ""
}
示例3: main
func main() {
s1 := "foo!bar"
s2 := "boo!bar!bazzz"
s3 := "doo"
fmt.Printf("%v\n", strings.SplitAfterN(s1, "!", 2))
fmt.Printf("%v\n", strings.SplitAfterN(s2, "!", 2))
fmt.Printf("%v\n", strings.SplitAfterN(s3, "!", 2))
fmt.Printf("%d\n", len(strings.SplitAfterN(s3, "!", 2)))
}
示例4: setConfigVal
func setConfigVal(val string, l string) {
// Set the config variable base on val in the line 1
// Config values are expected to be of the form foo="bar"
switch val {
case "tf_url":
v := strings.SplitAfterN(l, "=", 2)
tf_url = strings.Replace(strings.TrimSpace(v[1]), "\"", "", -1)
case "apikey":
v := strings.SplitAfterN(l, "=", 2)
apikey = strings.Replace(strings.TrimSpace(v[1]), "\"", "", -1)
}
}
示例5: Get
func (self *ProcState) Get(pid int) error {
contents, err := readProcFile(pid, "stat")
if err != nil {
return err
}
headerAndStats := strings.SplitAfterN(string(contents), ")", 2)
pidAndName := headerAndStats[0]
fields := strings.Fields(headerAndStats[1])
name := strings.SplitAfterN(pidAndName, " ", 2)[1]
if name[0] == '(' && name[len(name)-1] == ')' {
self.Name = name[1 : len(name)-1] // strip ()'s
} else {
return errors.New(fmt.Sprintf("Malformed process stats for pid %d", pid))
}
self.State = RunState(fields[0][0])
self.Ppid, _ = strconv.Atoi(fields[1])
self.Pgid, _ = strconv.Atoi(fields[2])
self.Tty, _ = strconv.Atoi(fields[4])
self.Priority, _ = strconv.Atoi(fields[15])
self.Nice, _ = strconv.Atoi(fields[16])
self.Processor, _ = strconv.Atoi(fields[36])
// Read /proc/[pid]/status to get the uid, then lookup uid to get username.
status, err := getProcStatus(pid)
if err != nil {
return fmt.Errorf("failed to read process status for pid %d. %v", pid, err)
}
uids, err := getUIDs(status)
if err != nil {
return fmt.Errorf("failed to read process status for pid %d. %v", pid, err)
}
user, err := user.LookupId(uids[0])
if err == nil {
self.Username = user.Username
} else {
self.Username = uids[0]
}
return nil
}
示例6: HandleTcpReading
func HandleTcpReading(channel ssh.Channel, term *terminal.Terminal, http map[string]string) {
defer channel.Close()
for {
line, err := term.ReadLine()
if err != nil {
break
}
logfile.Println(line)
if line == "" {
channel.Close()
return
}
if strings.Contains(line, ":") {
kv := strings.SplitAfterN(line, ":", 2)
http[kv[0]] = strings.TrimSpace(kv[1])
} else {
kv := strings.Fields(line)
if kv[0] == "POST" || kv[0] == "GET" {
http["Method"] = kv[0]
http["URI"] = kv[1]
} else {
http[kv[0]] = kv[1]
}
}
}
}
示例7: parseCommand
func parseCommand(rawCommand string) (*Command, error) {
parsed := strings.SplitAfterN(rawCommand, " ", 2)
parsed[0] = strings.TrimSpace(parsed[0])
command := new(Command)
switch parsed[0] {
case "USE":
dataLength := len([]rune(parsed[1]))
if dataLength == 0 {
return nil, errors.New("The command USE must have an valid queue name")
}
command.Command = Use
command.Data = parsed[1]
case "PUT":
dataLength := len([]rune(parsed[1]))
if dataLength == 0 {
return nil, errors.New("The command PUT cannot save an empty item")
}
command.Command = Put
command.Data = parsed[1]
case "GET":
command.Command = Get
case "PURGE":
command.Command = Purge
case "QUIT":
command.Command = Quit
default:
return nil, errors.New("Invalid command")
}
return command, nil
}
示例8: parseScalaDocFile
func parseScalaDocFile(f string, r io.Reader) []shared.Namespace {
d := xml.NewDecoder(r)
var t xml.Token
var err error
namespaces := []shared.Namespace{}
for ; err == nil; t, err = d.Token() {
if se, ok := t.(xml.StartElement); ok {
switch {
case se.Name.Local == "a" && hasAttr(se, "title", "Permalink"):
// <a href="../../index.html#[email protected][A,Repr]"
// title="Permalink"
// target="_top">
// <img src="../../../lib/permalink.png" alt="Permalink" />
// </a>
href, err := attr(se, "href")
if err == nil {
subs := strings.SplitAfterN(href, "#", 2)
if len(subs) > 1 {
n, err := parseNamespace(f, subs[0], subs[1])
if err != nil {
log.Println(err)
} else {
namespaces = append(namespaces, n)
}
}
}
}
}
}
return namespaces
}
示例9: printMongoOutput
// Use firstTime=true if this is the first time calling printMongoOutput() after startMongo()
func (sh *QShell) printMongoOutput(firstTime bool) error {
maxBytesReadAtOnce := 10000
buf := make([]byte, maxBytesReadAtOnce)
var recBytes []byte
for {
n, err := sh.mongoStateHolder.getPty().Read(buf)
if err != nil && err != io.EOF {
return err
}
if n == maxBytesReadAtOnce {
if err := sh.print("\nWARNING: Probably missing some of mongo's output"); err != nil {
return err
}
}
recBytes = append(recBytes, buf[:n]...)
rec := string(recBytes) // Very fast in Golang
// Terrible hacks to determine when mongo is finished printing output
if strings.Count(rec, "\r\n> ") == 2 || firstTime && strings.Count(rec, "\r\n> ") == 1 {
// Remove the "\r\n> " that mongo outputs
msg := strings.TrimSuffix(strings.TrimSpace(strings.Replace(rec, "\r\n> ", "\n", -1)), "\n")
if !firstTime {
// Remove the first line of mongo output, which is an echo of the user's input
msg = strings.SplitAfterN(msg, "\n", 2)[1]
}
if firstTime {
msg += "\n"
}
if err := sh.print(msg); err != nil {
return err
}
break
}
}
return nil
}
示例10: WorkLock
// WorkLock - Acquire consul for cluster to aquire right to schedule tasks.
func WorkLock() (err error) {
clusterID := os.Getenv("RDPGD_CLUSTER")
if clusterID == "" {
matrixName := os.Getenv(`RDPGD_MATRIX`)
matrixNameSplit := strings.SplitAfterN(matrixName, `-`, -1)
matrixColumn := os.Getenv(`RDPGD_MATRIX_COLUMN`)
for i := 0; i < len(matrixNameSplit)-1; i++ {
clusterID = clusterID + matrixNameSplit[i]
}
clusterID = clusterID + "c" + matrixColumn
}
key := fmt.Sprintf("rdpg/%s/tasks/work/lock", clusterID)
client, _ := consulapi.NewClient(consulapi.DefaultConfig())
workLock, err = client.LockKey(key)
if err != nil {
log.Error(fmt.Sprintf("tasks.WorkLock() Error Locking Work Key %s ! %s", key, err))
return
}
workLockCh, err = workLock.Lock(nil) // Acquire Consul K/V Lock
if err != nil {
log.Error(fmt.Sprintf("tasks.WorkLock() Error Acquiring Work Key lock %s ! %s", key, err))
return
}
if workLockCh == nil {
err = fmt.Errorf(`tasks.WorkLock() Work Lock not acquired`)
}
return
}
示例11: GetCommand
func GetCommand(body, from, dir string) (*exec.Cmd, error) {
split := strings.SplitAfterN(body, " ", 2)
cmd := strings.TrimSpace(split[0])
if !cmd_validator.MatchString(cmd) {
return nil, fmt.Errorf("Bad command \"%s\"", cmd)
}
var (
info os.FileInfo
err error
)
path := dir + Strip(cmd[1:])
if info, err = os.Stat(path); err != nil {
return nil, err
}
if info.IsDir() || info.Mode()&0111 == 0 {
return nil, fmt.Errorf("\"%s\" isn't executable", path)
}
args := []string{Strip(GetNick(from)), strconv.FormatBool(in(admin, from))}
if len(split) > 1 {
args = append(args, Strip(split[1]))
}
return exec.Command(path, args...), nil
}
示例12: AddObject
func (d *Directory) AddObject(obj *storage.Object) error {
name := strings.TrimPrefix(obj.Name, d.Prefix)
split := strings.SplitAfterN(name, "/", 2)
// Propagate update time to parent directories, excluding indexes.
// Used to detect when indexes should be regenerated.
if split[len(split)-1] != "index.html" {
objUpdated, err := time.Parse(time.RFC3339Nano, obj.Updated)
if err != nil {
return err
}
if d.Updated.Before(objUpdated) {
d.Updated = objUpdated
}
}
// Save object locally if it has no slash or only ends in slash
if len(split) == 1 || len(split[1]) == 0 {
d.Objects[name] = obj
return nil
}
sub, ok := d.SubDirs[split[0]]
if !ok {
sub = &Directory{
Bucket: d.Bucket,
Prefix: d.Prefix + split[0],
SubDirs: make(map[string]*Directory),
Objects: make(map[string]*storage.Object),
}
d.SubDirs[split[0]] = sub
}
return sub.AddObject(obj)
}
示例13: FindSauerbraten
func FindSauerbraten() string {
env := os.Environ()
best := ""
for i := range env {
current := strings.ToLower(env[i])
if strings.HasPrefix(current, "programfiles(x86)=") {
best = env[i]
break
}
if strings.HasPrefix(current, "programfiles=") {
best = env[i]
}
}
if best == "" {
return ""
}
split := strings.SplitAfterN(best, "=", 2)
if len(split) < 2 {
return ""
}
sauerbraten := path.Join(split[1], "Sauerbraten")
if futility.DirectoryExists(sauerbraten) {
return sauerbraten
}
return ""
}
示例14: EnvValue
func EnvValue(env string) string {
split := strings.SplitAfterN(env, "=", 2)
if len(split) < 2 {
return ""
}
return split[1]
}
示例15: main
func main() {
s := "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450"
var dstr []string = strings.SplitAfterN(s, "", len(s))
var dint [1000]int
n0 := 0
n1 := 0
n2 := 0
n3 := 0
n4 := 0
result := 0
for x := 0; x < len(s); x++ {
dint[x], _ = strconv.Atoi(dstr[x])
// fmt.Printf("dint[%v] is: %v\n", x, dint[x])
}
for i := 0; i < 996; i++ {
n0 = dint[i]
n1 = dint[i+1]
n2 = dint[i+2]
n3 = dint[i+3]
n4 = dint[i+4]
if n0*n1*n2*n3*n4 > result {
result = n0 * n1 * n2 * n3 * n4
}
}
fmt.Printf("Answer is: %v", result)
}