re: Find longest word in a given string VIEW POST

FULL DISCUSSION
 

perl

$_=qq|Iam a verrrrryyy longggggggg sentence|;
print( (sort{length($b) <=> length($a)} split(qq|\s|))[0])

Go

package main

import (
    "fmt"
    "strings"
)

func main() {
    s := "Iam a verrrrryyy longggggggg sentence"
    b := ""
    for _, w := range strings.Split(s, " ") {
        if len(w) > len(b) {
            b = w
        }
    }
    fmt.Println(b)

}

code of conduct - report abuse