Server Side Programming Articles - Page 364 of 2650

Golang program to show overloading of methods in class

Akhil Sharma
Updated on 01-Feb-2023 19:16:13

2K+ Views

In this article, we will learn how to overload the method in class using different example. Go programming language does not have concept of a class so function overloading will be used to execute the program. As a result, code can be more flexible and readable. As an illustration, you could create a function that accepts an interface as a parameter and then call it with several types that implement the interface. Let’s see it execution. Method 1: using custom type MyInt Here, it contains two methods Print() and PrintWithNumber() where values can be sent in these functions of MyInt ... Read More

Golang program to check if a string is empty or null

Akhil Sharma
Updated on 01-Feb-2023 19:15:03

17K+ Views

String in Golang is a collection of characters. Since strings in Go are immutable, they cannot be modified after they have been produced. Concatenating or adding to an existing string, however, enables the creation of new strings. A built-in type in Go, the string type can be used in a variety of ways much like any other data type. Syntax strings.TrimSpace() To eliminate leading and trailing white space from a string, use the strings.TrimSpace() function. Algorithm Step 1 − Create a package main and declare fmt(format package) package. Step 2 − Create a main function. Step 3 − Using internal ... Read More

Golang program to find the frequency of character in a string

Akhil Sharma
Updated on 01-Feb-2023 19:13:57

939 Views

String in Golang is a collection of characters. Since strings in Go are immutable, they cannot be modified after they have been produced. Concatenating or adding to an existing string, however, enables the creation of new strings. The frequency of a character means the number of times a character is appearing. Syntax map() To keep track of how frequently each character appears in the input string, the built-in map data structure in Go is used in example below. The map is an unsorted collection of key-value pairs with unique keys and variable types of values for the values. func ... Read More

Golang program to iterate through each character of string

Akhil Sharma
Updated on 01-Feb-2023 19:12:49

11K+ Views

A string in Golang is a collection of characters. Since strings in Go are immutable, they cannot be modified after they have been produced. Concatenating or adding to an existing string, however, enables the creation of new strings. A built-in type in Go, the string type can be used in a variety of ways much like any other data type. Syntax func len(v Type) int The len() function is used to get the length of any parameter. It takes one parameter as the data type variable whose length we wish to find and returns the integer value which is ... Read More

Golang program to capitalize first character of each word in a string

Akhil Sharma
Updated on 01-Feb-2023 19:11:55

8K+ Views

A string in Golang is a collection of characters. Since strings in Go are immutable, they cannot be modified after they have been produced. Concatenating or adding to an existing string, however, enables the creation of new strings. A built-in type in Go, the string type can be used in a variety of ways much like any other data type. Syntax strings.Join(words, ” ”) A slice of strings can be joined together with a separator using the join method. Two arguments are required by the function: a slice of strings, and a separator string. It gives back a single ... Read More

Golang program to create random strings

Akhil Sharma
Updated on 19-Jul-2023 14:31:01

178 Views

A string in Golang is a collection of characters. Since strings in Go are immutable, they cannot be modified after they have been produced. Concatenating or adding to an existing string, however, enables the creation of new strings. A built-in type in Go, the string type can be used in a variety of ways much like any other data type. Syntax rand.Seed(value) Rand.Seed() function is used to generate random numbers. It takes a user input as argument which is the upper limit for generating random numbers. func Now() Time The Now() function is defined in time package. this ... Read More

Golang program to clear the string buffer

Akhil Sharma
Updated on 01-Feb-2023 19:07:48

2K+ Views

When a string buffer is cleared, all of the data that was previously stored inside the buffer is deleted. This can be done for a variety of reasons, including when you want to reuse the buffer for fresh data or when the data that is currently in the buffer is no longer required. Here we will understand different techniques of clear a string buffer using go programming language Syntax Reset() Any accumulated data is discarded and the buffer is reset to zero using the Reset() method. The old buffer is essentially replaced with a new one and the old ... Read More

Golang program to check if a string contains a substring

Akhil Sharma
Updated on 01-Feb-2023 19:06:02

887 Views

A substring is a small string in a string and string in Golang is a collection of characters. Since strings in Go are immutable, they cannot be modified after they have been produced. Concatenating or adding to an existing string, however, enables the creation of new strings. A built-in type in Go, the string type can be used in a variety of ways much like any other data type. Syntax strings.Contains(str, substring string) To determine whether a string contains a particular substring, use the Contains(s, substr string) bool function. If the substring is found in the supplied string, a ... Read More

Golang program to show data hiding in class

Akhil Sharma
Updated on 01-Feb-2023 19:04:51

395 Views

In Golang, data hiding is a practice of preventing external code from accessing or changing a class’s members. This is accomplished by designating the class's members as private, which restricts access to or modification of them to the class's methods only. This is a crucial idea in object-oriented programming since it ensures the data's integrity and the class's proper operation. Syntax struct A struct is a composite data type used in the Go programming language that enables you to bring together related values of various types, such as a collection of fields or a collection of methods. Similar to ... Read More

What should you absolutely never do when using Python?

Vikram Chiluka
Updated on 31-Jan-2023 18:19:50

240 Views

In this article, we will learn what should never do when working with Python. Use Class Variables Carefully In Python, class variables are used as dictionaries and are referred to as Method Resolution Order (MRO). Furthermore, if a class lacks one attribute, then that class lacks a property. That is, if you modify what is in a class, other classes should not change as well. Improper Indentation In Python, indentation is everything. Python utilizes indentation online, unlike Java, C++, and other programming languages, which use curly brackets to construct code blocks. Many properties are affected by indentation. Some Python indentation ... Read More

Advertisements