How-to articles, tricks, and solutions about STRING

How to Use the StartsWith() and EndsWith() Functions in PHP

Sometimes, the work with PHP requires to check whether a string starts or ends with a particular string. Learn how to do it with the help of our tutorial.

In Java, how do I check if a string contains a substring (ignoring case)?

To check if a string contains a substring (ignoring case) in Java, you can use the contains method of the String class and the equalsIgnoreCase method.

Include constant in string without concatenating

In PHP, you can include a constant in a string without concatenating it by using double quotes (") instead of single quotes (') to define the string.

Java - removing first character of a string

To remove the first character of a string in Java, you can use the substring() method of the String class.

Java Byte Array to String to Byte Array

To convert a byte array to a string and back to a byte array in Java, you can use the getBytes method of the String class and the getBytes method of the Charset class.

Java int to String - Integer.toString(i) vs new Integer(i).toString()

In Java, there are several ways to convert an int value to a String:

Java String array: is there a size of method?

In Java, you can use the length field of an array to determine the size of the array. For example, given an array arr, you can get the size of the array using arr.length.

Java String new line

In JavaScript, you can use the following special characters to add a new line in a string:

Java string split with "." (dot)

To split a string in Java using a dot (.) as the delimiter, you can use the split method of the String class.

Java string to date conversion

To convert a string to a date in Java, you can use the parse method of the SimpleDateFormat class.

Java: convert List<String> to a join()d String

To convert a List&lt;String&gt; to a single string by joining the elements of the list with a separator, you can use the join() method of the java.util.StringJoiner class.

Java: how to initialize String[]?

There are several ways to initialize a String array in Java. Here are a few examples:

Java: method to get position of a match in a String?

To get the position of a match in a String in Java, you can use the indexOf() method of the String class.

Left padding a String with Zeros

To left pad a String with zeros in Java, you can use the String.format() method and the %0Nd format specifier, where N is the total length of the padded string.

PHP convert string to hex and hex to string

To convert a string to its hexadecimal representation, you can use the bin2hex function in PHP.

PHP remove all characters before specific string

You can use the strstr() function in PHP to remove all characters before a specific string.

PHP string "contains"

To check if a string contains another string in PHP, you can use the strpos() function.

PHP: Best way to extract text within parenthesis?

There are a few different ways to extract text within parentheses in PHP, depending on the specific requirements of your use case.

Print string to text file

In Python, you can use the built-in open() function to create a text file and write a string to it.

python: SyntaxError: EOL while scanning string literal

This error message is indicating that there is a problem with a string in your code.

Random string generation with upper case letters and digits

Here is a simple function that generates a random string of a given length using upper case letters and digits:

Read/Write String from/to a File in Android

To read and write a string from and to a file in Android, you can use the FileInputStream and FileOutputStream classes along with the InputStreamReader and OutputStreamWriter classes.

Remove all non-numeric characters from a string; [^0-9] doesn't match as expected

You can use the preg_replace function in PHP to remove all non-numeric characters from a string.

Remove all occurrences of char from string

To remove all occurrences of a particular character from a string, you can use the replace() method. This method takes two arguments: the string to be replaced, and the string to replace it with. If you pass an empty string as the second argument

Remove all special characters, punctuation and spaces from string

Here is an example of code that removes all special characters, punctuation, and spaces from a string in Python: