Tag: string

This tutorial will help you to check if a string contains any substring in PHP programming language. For example, you want to run a specific line of code only if any input string contains another substring in it. Example 1: The following code will evaluate to true because the main string $str contains the...

How to Find all files Containing Specific Text on Linux. This tutorial will help you to search all files containing specific string recursively. This tutorial uses “grep” command to search string in files. Alternatively, You can also use find command to search text. Command Syntax:- grep -rwl “search-string” /path/to/serch/dir 1. Search Single String in...

You can use Integer.parseInt() or Integer.valueOf() functions to convert String to int value. In case String is not a convertible then NumberFormatException will occur. #1. Using Integer.parseInt() Integer.parseInt() converts string value and returns an int primitive as result. For below example, first we store 5 as string value to id variable. Then convert it...

Java provides two options for string compare. First is == operator and second is .equals() function for Java string compare. This Java tutorial will help you to understand string comparison under Java and difference between == and .equals() for string comparison in Java. Operator == checks for the object reference and matches true if...

While working with php programming language, This article will help you to split comma, colon or any other delimited string in to array. Use php explode function to split delimited string to array. $myArray = explode(',', $myString); Example: Create a php script file and use following code. This example code is using command (,)...

Syntax: sed -i ‘/Text to Delete/d’ /path/to/file SED is an Stream Editor having capability to remove lines from file having specific string. Using -i with sed we can remove line in same file. Example 1: Remove all lines from /var/log/messages having string “DELETE THIS TEXT” and restore output in new file. Do not make...

Syntax: string.trim(); JavaScript trim() function is used for removing spaces before and after a string. Following example will help you to remove trailing and preceding white space using JavaScript . If you are searching for fixing issue with trim() function in old browsers, check below Example 2. Example 1: For example if a variable...

The JavaScript indexOf() method search for the substring in string and returns the position of the first occurrence of a specified substring. If substring not found, it returns -1. So you can use JavaScript IndexOf() method to check if a string contains substring in it. In this tutorial we will also provides example to...

Command: str3=”$str1 $str2″ The above example command will concatenate values of str1 and str2 stings and store it in third variable str3. Make sure there should not be any space before or after the assignment ( = ) operator. Example 1: It is simply write two or more strings variable one after one for...

Command: if [ “$str1” == “$str2” ] Example: Take input of two string in a script and compare if both are same or not, using if statement. Create a bash script using below content and execute. It will prompt for two strings from user and check if both string are same or not. #!/bin/bash...