You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

756 B

lastword

Instructions

Write a function LastWord that takes a stringand returns its last word followed by a\n`.

  • A word is a section of string delimited by spaces or by the start/end of the string.

Expected function

func LastWord(s string) string{

}

Usage

Here is a possible program to test your function :

package main

import (
	"piscine"

	"github.com/01-edu/z01"
)

func main() {
	z01.PrintRune(piscine.LastWord("this        ...       is sparta, then again, maybe    not"))
	z01.PrintRune(piscine.LastWord(" "))
	z01.PrintRune(piscine.LastWord(" lorem,ipsum "))
}

And its output :

$ go run . | cat -e
not$
$
lorem,ipsum$
$

Notions