Skip to content
Related Articles

Related Articles

strings.TrimLeftFunc() Function in Golang With Examples
  • Last Updated : 10 May, 2020

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:



filter_none

edit
close

play_arrow

link
brightness_4
code

// 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)
    }))
}

chevron_right


Output:

GeeksForGeeks!!!

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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)
    }))
}

chevron_right


Output:

34GeeksForGeeks!!!!
My Personal Notes arrow_drop_up
Recommended Articles
Page :