How-to articles, tricks, and solutions about STRING

Converting A String To Hexadecimal In Java

To convert a string to a hexadecimal string in Java, you can use the encodeHexString method of the org.apache.commons.codec.binary.Hex class.

Converting from a string to boolean in Python

In Python, you can use the bool() function to convert a string to a boolean.

Converting String to "Character" array in Java

To convert a string to a character array in Java, you can use the toCharArray method of the String class. This method returns a new character array that represents the same sequence of characters as the string.

Count the number of occurrences of a character in a string

You can use the .count() method to count the number of occurrences of a character in a string.

Delete particular word from string

In PHP, you can use the str_replace function to delete a particular word from a string.

Determine if a String is an Integer in Java

To determine if a string is an integer in Java, you can use the isDigit() method of the Character class to check if each character in the string is a digit. Here's an example:

Does Java have support for multiline strings?

In Java, there is no native support for multiline strings.

Does Python have a string 'contains' substring method?

Yes, Python has a string method called str.__contains__() that allows you to check if a string contains another string.

Filter pandas DataFrame by substring criteria

Here is an example of how you can filter a pandas DataFrame by substring criteria:

Get an OutputStream into a String

To get an OutputStream into a String, you can use a ByteArrayOutputStream as the OutputStream and then use the toString() method of the ByteArrayOutputStream to get the contents of the stream as a string.

Get PHP class property by string

In PHP, you can use the $ operator to access an object's properties by name.

Get string character by index

In Java, you can get a character at a specific index in a string using the charAt() method of the String class. This method takes an index as an argument and returns the character at that index.

Get the first letter of each word in a string

You can use the preg_match_all function in PHP to match all the words in a string and then use the substr function to get the first letter of each word.

How can I check if a single character appears in a string?

To check if a single character appears in a string in Java, you can use the indexOf method of the String class.

How can I pad a String in Java?

To pad a string in Java, you can use the String.format() method and specify a width for the string.

How can I prevent java.lang.NumberFormatException: For input string: "N/A"?

java.lang.NumberFormatException: For input string: "N/A" occurs when you try to parse a string that cannot be converted to a number, such as the string "N/A".

How can I print variable and string on same line in Python?

You can use the print() function in Python and use the + operator to concatenate a string and a variable.

How can I remove a substring from a given String?

There are several ways to remove a substring from a given string in Java. Here are a few options:

How can I remove part of a string in PHP?

There are several ways to remove a portion of a string in PHP.

How do I append one string to another in Python?

You can use the "+" operator to concatenate two strings in Python.

How do I convert a String to an InputStream in Java?

To convert a String to an InputStream in Java, you can use the ByteArrayInputStream class, which allows you to create an InputStream from a byte array.

How do I convert a String to an int in Java?

To convert a String to an int in Java, you can use the parseInt() method of the Integer class. Here's an example:

How do I convert all strings in a list of lists to integers?

Here is an example of how you might convert all strings in a list of lists to integers:

How do I convert from int to String in Java?

To convert an int to a String in Java, you can use the Integer.toString() method. For example