DEV Community

Discussion on: Find longest word in a given string

Collapse
 
vorsprung profile image
vorsprung • Edited

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)

}