gitlab.com/evatix-go/core@v1.3.55/coreutils/stringutil/FirstChar.go (about)

     1  package stringutil
     2  
     3  // FirstChar panics if not char
     4  func FirstChar(input string) byte {
     5  	return input[0]
     6  }
     7  
     8  // FirstCharOrDefault gives 0 if nothing present
     9  func FirstCharOrDefault(input string) byte {
    10  	if input == "" {
    11  		return 0
    12  	}
    13  
    14  	return input[0]
    15  }
    16  
    17  // LastChar panics if not char
    18  func LastChar(input string) byte {
    19  	return input[len(input)-1]
    20  }
    21  
    22  func LastCharOrDefault(input string) byte {
    23  	if input == "" {
    24  		return 0
    25  	}
    26  
    27  	return LastChar(input)
    28  }