Posts Tagged ‘replace’

Replace white spaces – blank spaces in string using Javascript

September 27, 2010 Leave a comment

Regex make our life simpler, and when used properly can create miracles. One such example  Regex is given below which replaces white spaces/blank spaces in string using javascript :

function ReplaceWhiteSpaces()
 var text = "Example to Replace white spaces in strings";
 text = text.replace(/\s/g, "-");

Output : Example-to-Replace-white-spaces-in-strings

Regex Used : /\s/g

Using Replace() function in Sql Server

In this article, we will be talking about one of the important inbuilt functions of sql server, Replace()


REPLACE ( string_expression , string_pattern , string_replacement )

Some examples of using replace are as follows:


select replace('Nice Article', 'Nice','Cool')

returns Cool Article


UPDATE emp set designation=replace(designation, 'Sales', 'Marketing') where department='Marketing'