Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go equivalent of PHP's 'implode'

Tags:

php

go

implode

What is the Go equivalent of PHP's 'implode'?

like image 820
code_martial Avatar asked Aug 23 '12 09:08

code_martial


People also ask

What is implode () in PHP?

The implode() is a builtin function in PHP and is used to join the elements of an array. implode() is an alias for PHP | join() function and works exactly same as that of join() function. If we have an array of elements, we can use the implode() function to join them all to form one string.

What are the uses of explode () and implode () functions in PHP?

PHP Explode function breaks a string into an array. PHP Implode function returns a string from an array. PHP implode and PHP explode are two common functions used in PHP when working with arrays and strings in PHP.

What is the difference between implode and join in PHP?

join appends the delimiter to the last element while implode doesn't.

What is the first parameter of the implode () function?

The first parameter is 'separator' The separator is the optional parameter, and it is there to specify what is needed to be put between the array components. By default, it appears as ”, “ which denotes an empty string. The array values are joined to form a string and are separated by the separator parameter.


2 Answers

In the standard library: strings.Join

func Join(a []string, sep string) string 

http://golang.org/pkg/strings/#Join

Cheers!

like image 92
thwd Avatar answered Sep 22 '22 00:09

thwd


Join in the strings library. It requires the input array to be strings only (since Go is strongly typed).

Here is an example from the manual:

s := []string{"foo", "bar", "baz"} fmt.Println(strings.Join(s, ", ")) 
like image 24
Emil Vikström Avatar answered Sep 21 '22 00:09

Emil Vikström