How-to articles, tricks, and solutions about STRING

How do I create a Java string from the contents of a file?

To create a Java string from the contents of a file, you can use the following code:

How do I get a substring of a string in Python?

To get a substring of a string in Python, you can use the string[start:end] notation.

How do I get the filename without the extension from a path in Python?

To get the filename without the extension from a file path in Python, you can use the os.path.splitext() function.

How do I get the last character of a string?

To get the last character of a string in Java, you can use the charAt() method of the String class, which returns the character at a specific index in the string.

How do I lowercase a string in Python?

You can use the lower() method to lowercase a string in Python.

How do I pad a string with zeroes?

You can use the zfill() method to pad a string with zeros on the left side.

How do I print curly-brace characters in a string while using .format?

To print a curly brace character in a string that is being formatted with the .format() method, you will need to use double curly braces to escape the character.

How do I print my Java object without getting "SomeType@2f92e0f4"?

To print a Java object in a more readable format, you can override the toString() method in your class.

How do I put a variable’s value inside a string (interpolate it into the string)?

In Python, you can use the format() method or f-strings (available in Python 3.6 and above) to interpolate a variable's value into a string.

How do I read / convert an InputStream into a String in Java?

There are several ways to read an InputStream and convert it to a String in Java. One way is to use the BufferedReader and InputStreamReader classes to read the InputStream line by line, and use a StringBuilder to construct the final String:

How do I remove a substring from the end of a string?

To remove a substring from the end of a string, you can use the rsplit() method and specify the substring as the delimiter.

How do I remove the last comma from a string using PHP?

To remove the last comma from a string in PHP, you can use the rtrim function.

How do I reverse a string in Python?

To reverse a string in Python, you can use the following method:

How do I split a string into a list of characters?

In Python, you can use the built-in list() function to convert a string into a list of characters.

How do I split the definition of a long string over multiple lines?

You can split a string over multiple lines by using triple quotes, either ''' or """ .

How do I trim whitespace from a string?

There are a few ways to trim whitespace from a string in Python.

How do I trim whitespace?

In Python, you can use the .strip() method to remove leading and trailing whitespace from a string.

How To Add New Elements To A JavaScript Array

To add new elements you can use the following JavaScript functions: push() unshift(), concat() function or splice(). See examples.

How to add new elements to an array in Java?

To add new elements to an array in Java, you have a few options: If you know the size of the array in advance and the array is not full, you can simply assign a new value to an unused element in the array.

How to capitalize the first character of each word in a string

There are a few different approaches you can take to capitalize the first character of each word in a string in Java.

How to Capitalize the First Letter in a String in JavaScript

Read this JavaScript tutorial and learn the methods and undertake some steps which will help you make the first letter in the string uppercase easily.

How to capitalize the first letter of a String in Java?

To capitalize the first letter of a string in Java, you can use the toUpperCase method of the java.lang.String class. Here's an example of how you can do this:

How to change a string into uppercase?

In Python, you can use the built-in upper() method to change a string to uppercase.

How to change date format in a Java string?

To change the date format in a Java string, you can use the SimpleDateFormat class.

How to Check for Empty/Undefined/Null String in JavaScript

In this tutorial, we are going to show you the ways of checking whether the JavaScript string is empty, undefined, or null. Just follow the guidelines.