<\/span><\/h1>\n\n\n\nstrings<\/strong> package of GO provides a ReplaceAll<\/strong> method that can be used to replace all non-overlapping instances of a given substring with a new substring. We can use this method to delete a substring by providing the replacement of the substring to be deleted as an empty string<\/p>\n\n\n\nBelow is the signature of the function. The function will replace all non-overlapping instances of old<\/strong> with new<\/strong> in string s<\/strong>. To delete a substring we can supply that substring as old <\/strong>and new <\/strong>as an empty string <\/p>\n\n\n\nfunc ReplaceAll(s, old, new string) string<\/code><\/pre>\n\n\n\nLet’s look at the working code<\/p>\n\n\n\n
<\/span>Code:<\/strong><\/span><\/h1>\n\n\n\npackage main\n\nimport (\n \"fmt\"\n \"strings\"\n)\n\nfunc main() {\n res = strings.ReplaceAll(\"abcabcabcdef\", \"ab\", \"\")\n fmt.Println(res)\n}<\/code><\/pre>\n\n\n\nOutput:<\/strong><\/p>\n\n\n\ncccdef<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"Table of Contents OverviewCode: Overview strings package of GO provides a ReplaceAll method that can be used to replace all non-overlapping instances of a given substring with a new substring. We can…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[],"class_list":["post-1781","post","type-post","status-publish","format-standard","hentry","category-tech"],"yoast_head":"\n
Find and delete a substring in Go (Golang) - Welcome To Golang By Example<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n