Software engineering and personal development

Tag: string (Page 2 of 2)

How to Find the Index of a Substring in a string

file cabinet
Photo by Maksym Kaharlytskyi on Unsplash

Many programming interview questions have something to do with working with indexes. You may also be dealing with tasks at work that can have something to do with indexes.

One such task can be doing different splits and formattings of text files based on an index of a specific character.

Let us assume that you are asked to remove part of a string based on a certain index in a string.

Continue reading

How to Quickly Check Whether a Variable is a Number in Python

photo of man walking near LED signage
Photo by Ryoji Iwata on Unsplash

Since you don’t have a predefined type for a variable in Python, you may notice a lot of bugs that can arise. As such, it is very important that you pay a lot of attention in cases when you have to make sure that you are using the correct type of variable.

This can also be the case when you expect a variable to be a number, but you get a string or any other type instead.

Continue reading

How to Quickly Repeat String without Looping in Python

green clothes hanger
Photo by Keagan Henman on Unsplash

You have been doing math calculations since a very young age, from adding two numbers, to multiplying, dividing, and finding the square root of a number by hand.

In Python, you can also multiply a string with a number.

Yes, you read that right. You do not have to do something big, or fancy: You can just take a string and multiply it with any natural number.

You may be wondering, “What’s the result? I know what is 3 * 3, but I don’t know what’s going to be the result of 3 * ‘abc’?

Continue reading

Remove all whitespace in your strings with the squish method in your Ruby projects

It is really hard to think about a real world project in which you are not going to have strings. As a result, having pre-existing methods for manipulating strings is really productive, as it saves you time. In today’s article, I want to emphasize a particular method in Ruby on Rails, that’s surprisingly not that much well known, which helps you with the whitespaces. Continue reading

A very efficient way to do string concatenations in Ruby

Img source: medium.com

It is very difficult to think about an application that does not have any string data type. Names, emails, object attributes, etc. are very common. Knowing their wide usages, it is obvious that we should at least learn the best practices about them. I recently learned about the difference between the efficiency of two similar string functions, which was a bit surprising and that made me write this article. Although both methods do the concatenation of strings, there is a big difference in their performance.

Continue reading

How to change the default new line delimiter in Ruby

 

One of the core pillars of motivation is having the opportunity to use some form of autonomy at the work that you do. Ruby programming language allows you to do just that with a lot of its built-in features. It gives you the ability to override methods of basic built-in classes, methods and also attributes. One such attribute in which we will focus on this article is the ability to change the default new line delimiter. Continue reading

Newer posts »

© 2024 Fatos Morina

Theme by Anders NorenUp ↑