Found 1082 Articles for Go Programming

Golang Program to Convert String to Object

Akhil Sharma
Updated on 16-Feb-2023 18:04:45

2K+ Views

In Golang program, a string is a data type that contains literals and characters whereas an object is a data type created from classes by keeping similar types of properties together. In this article, we will look at two methods by which we can convert a string to an object in go programming language. Syntax func Split(str, sep string) []string Split() function is used to split a string through a provided separator. This function is present in strings package and it accepts the string to split as an argument along with a separator. The function then returns the final ... Read More

Golang program to replace a character at a specific index

Akhil Sharma
Updated on 13-Feb-2023 15:46:44

1K+ Views

In this tutorial, we will inculcate how to replace a character at a specific index using few examples. The output will be printed on the console using fmt.Println() function. Let’s dive deep into the examples and see how it’s done. Method 1: Using Replace Function In this method, we will learn how to replace a character at a specific index using replace function. The output is printed on console using fmt.Println() function. Let’s understand this through the code. Syntax func Replace(str, oldstr, newstr string, m int) string This function is used to return the copy of the string which ... Read More

Golang Program to remove all 'nil' elements from the array

Akhil Sharma
Updated on 13-Feb-2023 15:44:10

916 Views

This tutorial is all about how to remove all nil elements from the array. Basically, sometimes there are empty strings present in the array which we want to remove. Here in this tutorial, we will have a look how to remove those strings with the use of very simple methods. Method 1: Using helper Function Approach In this method, we will see how to remove null elements using helper function approach. The array will be taken as a parameter in the function and the output will be printed on console using print statement of Golang. Syntax func append(slice, element_1, element_2…, ... Read More

Golang program to iterate over a Slice

Akhil Sharma
Updated on 13-Feb-2023 15:38:02

2K+ Views

In this tutorial, we will iterate over a slice using different set of examples. A slice is a dynamic sequence which stores element of similar type. The iterated list will be printed on the console using fmt.Println() function. Method 1:Using for Loop with Index In this method, we will iterate over a slice using for loop where both the index and its element will be printed on the console screen. Let’s have a look how to execute this example. Algorithm Step 1 − Create a package main and import fmt package in the program. Step 1 − Create a package ... Read More

Golang program to fill an array with a specific element

Akhil Sharma
Updated on 13-Feb-2023 15:35:44

2K+ Views

In this tutorial, we will learn how to fill an array with a specific element. We will explore few examples to know more about this program. The output will be printed on console using fmt.Println() function. Let’s have a look and understand the program. We have used the following make() function in the examples. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments. Method 1: Using for Loop and Make Function in Main Function ... Read More

Golang program to find the prime numbers from the array

Akhil Sharma
Updated on 13-Feb-2023 15:31:52

335 Views

In this tutorial, we will showcase how to find the prime numbers from the array using different examples. Prime numbers are those numbers which are either divisible by 1 or by themselves they have no factor other than this. Now we will present you few illustrations to help you get clear with the logic behind this program. Method 1: Finding Prime Number in the main Function In this particular method, we will print the prime numbers with the help of nested for loops. We will half the array elements in every inner iteration and check whether they are divisible or ... Read More

Golang program to fetch elements from an array based on an index

Akhil Sharma
Updated on 13-Feb-2023 15:26:59

716 Views

In this tutorial, we will learn how to fetch elements from an array with the help of index using different examples to showcase what methods can be applied to it and the result obtained will be printed on the console using the print function in Golang. Method 1: Using an Array Index In this method, we will see how to fetch element from an array using index in for loop and this is one of the simplest methods to solve this problem, lets have a look at this example to understand it. Algorithm Step 1 − Create a package main ... Read More

Golang Program to remove given element from the array

Akhil Sharma
Updated on 13-Feb-2023 15:25:24

3K+ Views

In this tutorial, we will learn how to remove an element from an array using simple for loop approach. The logic behind this approach is that create a new array and the particular index element which is to be removed don’t add it to the new array. Let’s have a look how to execute it with the use of different examples. Remove Element from the Array in main Function In this method, we will execute the entire program inside main function. An original array and a new array will be created to execute the removal of elements from the array. ... Read More

Golang program to illustrate the creation of strings

Akhil Sharma
Updated on 13-Feb-2023 15:21:26

108 Views

In this tutorial, we will see how strings are created in Golang. There are different ways to create strings which we will learn via some examples. In Golang a string is a sequence of variable-width characters where each character is represented by one or more bytes. Method 1: Using double Quotes with Shorthand Declaration In this method, we will learn about how to create strings using shorthand declaration. Let’s dive into the code to understand it. Algorithm Step 1 − Create a package main and import fmt package in the program. Step 2 − Create a function main and further ... Read More

Golang Program to search an item into the array using interpolation search

Akhil Sharma
Updated on 13-Feb-2023 15:17:57

186 Views

In this tutorial, we will see how to search an item in the array using interpolation search. It is very similar to Binary search but is an improved version of it, in this algorithm the element is searched from the sorted array using a different method to find middle element and the output is printed using print function in Golang. Let’s have a look to understand it − Using interpolation search in main method In this method, we will learn how to search an element in the array using an interpolation search method. All the things will be executed in ... Read More

Advertisements