Join Function
Lesson 13 of 19 in Coddy's Functions and Pointers in Golang course.
In Go language, there is a function that takes two strings and concatenates them into one string.
An example of how this function works:
str1 := "Coddy"
str2 := "Tech"
final := strings.Join([]string{str1, str2}, ".")
fmt.Println(final)The function is called Join, and it's defined inside the strings package. It takes a slice of strings []string as input. In this example, we pass our variables that we need to concatenate, str1 and str2, and the third parameter specifies what we need to put in between them. In this example, it's a dot ".", but it could be anything you want.
And as a result, we get:
Coddy.TechChallenge
EasyLet's build our Join function! 😁
Write a function called concatenate that takes three strings and returns a string.
The first two strings are the strings that we want to concatenate, and the third one is the character or the value that we're going to put in between them.
Try it yourself
// Your Code Here
All lessons in Functions and Pointers in Golang
1Introduction
Introduction4Rebuild Go Strings Functions
Strings in GolangJoin FunctionContains FunctionIndex FunctionRecap Challenge #1