Open In App

strings.TrimLeftFunc() Function in Golang With Examples

Last Updated : 10 May, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

strings.TrimLeftFunc() Function returns a slice of the string s with all leading Unicode code points c satisfying f(c) removed.

Syntax:

func TrimLeftFunc(s string, f func(rune) bool) string

Here, s is the string and func() is the method which satisfies the string characters.

Return Value: It returns the string after removing the leading characters from the string.

Example 1:




// Golang program to illustrate
// the strings.TrimLeftFunc() Function
package main
   
// importing fmt, unicode and strings
import (
    "fmt"
    "strings"
    "unicode"
)
   
// Calling Main method
func main() {
   
    // Here we have a string. The function
    // returns true for the letters
    // and all other will trim out
    // from the string only from Left
    fmt.Print(strings.TrimLeftFunc("77GeeksForGeeks!!!", func(r rune) bool {
        return !unicode.IsLetter(r)
    }))
}


Output:

GeeksForGeeks!!!

Example 2:




// Golang program to illustrate
// the strings.TrimLeftFunc() Function
package main
   
// importing fmt, unicode and strings
import (
    "fmt"
    "strings"
    "unicode"
)
   
// Calling Main method
func main() {
   
    // Here we have a string. The function
    // returns true for the letters
    // and numbers as well
    // and all other will trim out
    // from the string only from left
    fmt.Print(strings.TrimLeftFunc("!!!34GeeksForGeeks!!!!", func(r rune) bool {
        return !unicode.IsLetter(r) && !unicode.IsNumber(r)
    }))
}


Output:

34GeeksForGeeks!!!!


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads