How can i replace symbols

Is there a way to replace symbols in a text? This is what i did…not sure what im doing wrong
https://play.golang.org/p/u-LO3B4LaJL

1 Like

Tried ranging through the strings, and getting a rune. But that made it complicated for me

1 Like

‘strings’ have some funcs to replace item in a string.
Also Go has a package for regular expressions (‘regexp’)

1 Like

Hi Justin, can you explain what do you want to get from the function?
Or some examples of the results you expect?

Regards

1 Like

Im trying to make a function that replaces all " symbols with ’ and vice versa. so if i see ", it should replace it with ’

1 Like

Here is an example:
https://play.golang.org/p/7WWWt4tqjag

package main

import (
	"fmt"
	"strings"
)

func main() {
	s := ` a : " ", b : ' ' `
	fmt.Println(s)
	one := replaceDobleQuotetoQuote(s)
	two := replaceQuotetoDobleQuote(s)
	fmt.Println(one)
	fmt.Println(two)

}

func replaceDobleQuotetoQuote(s string) string {
	return strings.ReplaceAll(s, `"`, `'`)
}

func replaceQuotetoDobleQuote(s string) string {
	return strings.ReplaceAll(s, `'`, `"`)
}
2 Likes

Hi

Something like this: https://play.golang.org/p/nxZJD4cEkA9

4 Likes

Thanks a lot.

2 Likes

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