Search and Replace First Occurrence of Character in MySQL

Samual Sam
Updated on 30-Jul-2019 22:30:25

3K+ Views

You can achieve this with the help of CONCAT() along with REPLACE() function. To find the first occurrences you need to use INSTR() function.The syntax is as follows −UPDATE yourTableName SET UserPost = CONCAT(REPLACE(LEFT(yourColumnName, INSTR(yourColumnName, 'k')), 'k', 'i'), SUBSTRING(yourColumnName, INSTR(yourColumnName, 'k') + 1));To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table UserInformation -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserName varchar(10), -> UserPost text -> ); Query OK, ... Read More

Generation of Rectangular Wave Using DAC Interface

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

742 Views

We write a program for the generation of rectangular interface of Digital to Analog Converter (DAC) interference: Let us consider a problem solution in this domain. The problem states that: To get unipolar output, J1 is shorted to J2 on the interface. To display the waveform on a CRO connect pin 1 of connector P1 to CRO signal pin, and pin 2 of connector P1 to CRO ground pin.The program is stated as below.; FILE NAME DAC_TO_RECT.ASM ORG C100H X DW 00FFH ; ‘OFF’ time is proportional to this value Y DW 00C0H ; ‘ON’ time is proportional to this value ... Read More

Iterate Through Quintet Class in Java Tuples

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

130 Views

You can iterate through Quintet class using a loop, like arrays in Java.Let us first see what we need to work with JavaTuples. To work with Quintet class in JavaTuples, you need to import the following package −import org.javatuples.Quintet;Note − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Quintet Class in JavaTuples, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport org.javatuples.Quintet; public class Demo {    public static void main(String[] args) {       ... Read More

Set Web View Render Priority in Android

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

886 Views

This example demonstrates about How to set Web view Render Priority in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. In the above code, we have taken web view to show tutorialspoint.com.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.app.ProgressDialog; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.widget.EditText; public class MainActivity extends AppCompatActivity {    @RequiresApi(api ... Read More

IntStream limit() Method in Java

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

1K+ Views

The limit() method of the IntStream class is used to return a stream consisting of the elements of this stream, truncated to be no longer than maxSize in length. Here, maxSize is the parameter.The syntax is as followsIntStream limit(long maxSize)Here, the maxSize parameter is the count of elements the stream is limited to.At first, an IntStream is created with the range() method to set a sequential order of elementsIntStream intStream = IntStream.range(20, 40);Now, use the limit() method, whose parameter is the maxSize i.e. the count of elements the stream is limited tointStream.limit(8)The following is an example to implement IntStream limit() ... Read More

Search Document in MongoDB by ID

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

428 Views

To search a document in MongoDB by _id, you need to call ObjectId(). Let us first see the syntaxdb.yourCollectionName.find({"_id":ObjectId("yourId")}).pretty();To understand the concept and search a document, let us implement the following query to create a collection with documents> db.searchDocumentDemo.insertOne({"UserId":1, "UserName":"Larry"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c97a8e4330fd0aa0d2fe487") } > db.searchDocumentDemo.insertOne({"UserId":2, "UserName":"Mike"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c97a8ea330fd0aa0d2fe488") } > db.searchDocumentDemo.insertOne({"UserId":3, "UserName":"David"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c97a8f1330fd0aa0d2fe489") } > db.searchDocumentDemo.insertOne({"UserId":4, "UserName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c97a8fa330fd0aa0d2fe48a") } > db.searchDocumentDemo.insertOne({"UserId":5, "UserName":"Robert"}); {    "acknowledged" : true,    "insertedId" : ... Read More

Convert BOOL to INT in MySQL

George John
Updated on 30-Jul-2019 22:30:25

1K+ Views

To convert bool to int in MySQL, you can use CAST(). Let us first create a table:mysql> create table convertBoolToIntDemo -> ( -> isYoung bool -> ); Query OK, 0 rows affected (0.69 sec)Following is the query to insert some records in the table using insert command:mysql> insert into convertBoolToIntDemo values(true); Query OK, 1 row affected (0.18 sec) mysql> insert into convertBoolToIntDemo values(false); Query OK, 1 row affected (0.09 sec) mysql> insert into convertBoolToIntDemo values(true); Query OK, 1 row affected (0.15 sec) mysql> insert into convertBoolToIntDemo values(false); Query ... Read More

Get Temporal Queries Precision in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

156 Views

To get Temporal Queries precision, use the TemporalQuery interface with the precision() method of the TemporalQueries −TemporalQueryprecision = TemporalQueries.precision(); Get the precision for LocalDate: LocalDate.now().query(precision) Get the precision for LocalTime: LocalTime.now().query(precision) Get the precision for YearMonth: YearMonth.now().query(precision) Get the precision for Year: Year.now().query(precision)Exampleimport java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.Year; import java.time.YearMonth; import java.time.temporal.TemporalQueries; import java.time.temporal.TemporalQuery; import java.time.temporal.TemporalUnit; public class Demo {    public static void main(String[] args) {       TemporalQueryprecision = TemporalQueries.precision();       System.out.println("TemporalQueries precision...");       System.out.println(LocalDate.now().query(precision));       System.out.println(LocalTime.now().query(precision));       System.out.println(LocalDateTime.now().query(precision));       System.out.println(YearMonth.now().query(precision));       System.out.println(Year.now().query(precision)); ... Read More

Return a Specific Field in MongoDB

Samual Sam
Updated on 30-Jul-2019 22:30:25

387 Views

Too return a specific field, use the find() method in MongoDB. Let us first create a collection with documents −> db.specificFieldDemo.insertOne({"FirstName":"John", "LastName":"Doe"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb8019a623186894665ae31") } > db.specificFieldDemo.insertOne({"FirstName":"John", "LastName":"Smith"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb801ab623186894665ae32") } > db.specificFieldDemo.insertOne({"FirstName":"David", "LastName":"Miller"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb801b3623186894665ae33") } > db.specificFieldDemo.insertOne({"FirstName":"Sam", "LastName":"Williams"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb801bf623186894665ae34") }Following is the query to display all documents from the collection with the help of find() method −> db.specificFieldDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cb8019a623186894665ae31"),   ... Read More

Refresh Activity When IntentService is Finished in Android

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

791 Views

Before getting into the example, we should know what Intent service is in android. Intent Service is going to do background operation asynchronously. When user call startService() from activity, it doesn’t create an instance for each request and it going to stop service after done some action in service class or else we need to stop service using stopSelf().This example demonstrates How to refresh Activity when IntentService is finished.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code ... Read More

Advertisements