Is There Any Special Character For String Termination

Hello Reader,
I am working on function to remove the whitespace from begginning and ending of string

package Madhur

// This package will alter the user name if there are white spaces in name of string

// this will remove the white spaces (if any) from string

func Remove_Whitespc(word string) string {

// str is converted to byte a string are immutable
str := []byte(word)
if str[0] == ' '{
	for i := 0; i < len(str) - 1; i++ {
		str[i] = str[i+1]

return string(str)


1 Like

Why not use the Trim function from the “strings” package in the standard library?

In your case you could do:

`strings.Trim(word, " ")`

Example from the documentation:

package main

import (

func main() {
	fmt.Print(strings.Trim("¡¡¡Hello, Gophers!!!", "!¡"))

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.