To find rows and update with new value where column value ends with specific substring you need to use LIKE operator.The syntax is as follows:UPDATE yourTableName SET yourColumnName=’yourValue’ WHERE yourColumnName LIKE ‘%.yourString’;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table RowEndsWithSpecificString -> ( -> Id int NOT NULL AUTO_INCREMENT, -> FileName varchar(30), -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (1.50 sec)Now you can insert some records in the table using ... Read More
DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. Let us set DecimalFormat("##E0") and use the format() method as well.DecimalFormat decFormat = new DecimalFormat("##E0"); System.out.println(decFormat.format(-189.8787)); System.out.println(decFormat.format(8.19)); System.out.println(decFormat.format(9897.88));Since, we have used DecimalFormat class in Java, therefore importing the following package is a must −import java.text.DecimalFormat;The following is the complete example −Example Live Demoimport java.text.DecimalFormat; public class Demo { public static void main(String[] argv) throws Exception { DecimalFormat decFormat = new DecimalFormat("##E0"); System.out.println(decFormat.format(-189.8787)); System.out.println(decFormat.format(8.19)); ... Read More
The str_replace version in MySQL is the replace() function. Let us first create a table to understand the function −mysql> create table StringReplaceDemo −> ( −> Id int, −> URL varchar(200) −> ); Query OK, 0 rows affected (0.38 sec)Insert some records in the table with the help of insert command. The query is as follows −mysql> insert into StringReplaceDemo values(1001, 'https://www.google.co.in'); Query OK, 1 row affected (0.09 sec) mysql> insert into StringReplaceDemo values(1002, 'https://www.facebook.com'); Query OK, 1 row affected (0.11 sec) mysql> insert into StringReplaceDemo ... Read More
To draw a route between two Locations on map we need to have co-ordinates of both those locations.Once we have the co-ordinates of both locations we can use the below given function to show the line between two points on map. In this example I’ll be using two random location as two points.func getDirections(loc1: CLLocationCoordinate2D, loc2: CLLocationCoordinate2D) { let source = MKMapItem(placemark: MKPlacemark(coordinate: loc1)) source.name = "Your Location" let destination = MKMapItem(placemark: MKPlacemark(coordinate: loc2)) destination.name = "Destination" MKMapItem.openMaps(with: [source, destination], launchOptions: [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]) }We’ll call this function in ViewDidLoad for this tutorial to show the ... Read More
All the words that start with a can be found in a string by using regular expressions in Java. The regular expressions are character sequences that can be used to match other strings using a specific pattern syntax. The regular expressions are available in the java.util.regex package which has many classes but the most important are Pattern class and Matcher class.A program that finds all words that start with an 'a' is using regular expressions is given as follows:Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo { public static void main(String args[]) throws Exception { String ... Read More
If your cast does not work, then you can use yourColumnName*1 with ORDER BY clause.Using yourColumnName*1. The syntax is as follows:SELECT yourColumnName1, yourColumnName2, ...N FROM yourTableName ORDER BY yourColumnName*1 DESC;You can also use CAST() operator. The syntax is as follows:SELECT yourColumnName1, yourColumnName2, ...N FROM yourTableName ORDER BY CAST(yourColumnName as DECIMAL(8, 2)) DESC;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table VarcharColumnAsFloatDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Amount varchar(20), -> PRIMARY KEY(Id) ... Read More
DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. Let us set DecimalFormat("###E0") and use the format() method as well.DecimalFormat decFormat = new DecimalFormat("##E0"); System.out.println(decFormat.format(-267.9965)); System.out.println(decFormat.format(8.19)); System.out.println(decFormat.format(9897.88));Since we have used DecimalFormat class in Java, therefore importing the following package is a must −import java.text.DecimalFormat;The following is the complete example −Example Live Demoimport java.text.DecimalFormat; public class Demo { public static void main(String[] argv) throws Exception { DecimalFormat decFormat = new DecimalFormat("###E0"); System.out.println(decFormat.format(-267.9965)); System.out.println(decFormat.format(8.19)); ... Read More
Using the SimpleDateFormat(“E, dd MMM yyyy HH:mm:ss Z”), wherein E is for Day of Week −// displaying current date and time Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z"); System.out.println("Today's date and time = "+simpleformat.format(cal.getTime()));Since we have used the Format and SimpleDateFormat class above, therefore import the following packages. With that, we have also used the Date −import java.text.Format; import java.text.SimpleDateFormat; import java.util.Date;The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { ... Read More
You can order by length of characters with the help of CHAR_LENGTH() function from MySQL. The function returns the number of characters i.e. 4 for the following string −AMITTo order strings by length of characters, the following is the syntax −select *from yourTableName order by CHAR_LENGTH(yourColumnName);To understand the above concept, let us first create a table. The following is the query to create a table −mysql> create table OrderByCharacterLength −> ( −> BookName varchar(200) −> ); Query OK, 0 rows affected (1.97 sec)Insert some records in the table with the help of insert command. The query is ... Read More
A greedy qualifier repeats the specified token as many times as possible and then the engine backtracks and the greedy qualifier gives up matches to eventually find the required match.The regex "(\w+)(\d)(\w+)" is used to find the match in the string "EarthHas1Moon".A program that demonstrates this is given as follows:Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo { public static void main(String args[]) { String str = "EarthHas1Moon"; String regex = "(\w+)(\d)(\w+)"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(str); m.find(); ... Read More