Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find sub-string and replace it?

I have the following rows:

Name               Url
name1              http://foo.com/this/that
name6              http://that.net/hello
name2              http://foo.com/hello/world
name3              http://foo.com/world/hello
name4              http://hello.com/this/that

I need to write a query that will change every foo.com to hello.com.

Any ideas?

like image 497
PhilBrown Avatar asked Mar 18 '11 14:03

PhilBrown


People also ask

How do you replace a sub string?

replace() Parameters The replace() method can take maximum of 3 parameters: old - old substring you want to replace. new - new substring which will replace the old substring. count (optional) - the number of times you want to replace the old substring with the new substring.

How do you find sub strings?

The substring() method extracts characters, between two indices (positions), from a string, and returns the substring. The substring() method extracts characters from start to end (exclusive). The substring() method does not change the original string.

How do you replace a particular substring in Java?

One of the simplest and straightforward methods of replacing a substring is using the replace, replaceAll or replaceFirst of a String class.


1 Answers

UPDATE <table name> SET Url = REPLACE (Url, "foo.com" , "hello.com")
like image 155
CoolStraw Avatar answered Sep 27 '22 23:09

CoolStraw