Archive

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, "-");
 alert(text);
}

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

Regex Used : /\s/g

Advertisements

Using Replace() function in Sql Server

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

Syntax:

REPLACE ( string_expression , string_pattern , string_replacement )

Some examples of using replace are as follows:

1)

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

returns Cool Article

2)

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