![]() |
VOOZH | about |
In this article, we will see how to select a string from the text and replace it with another string using AngularJS and will understand it through the illustrations. The replace() method can be used to search the particular character(s), which is getting replaced with a specific character(s) & return a new generated string.
Syntax:
string.replace(char findChar, char replacedChar);
Parameter Values:
Return Value: It returns the new string containing the new character(s) that have replaced the specified character(s).
Approach: The approach is utilizing the replace() method and replacing the content of the string with the new one. In the first example, the string 'Welcome User' is replaced by the word 'Geek' in place of 'User'. In the second example, the word 'User' is replaced by the string user enters in the input element.
Example 1: In this example, the word "User" is getting replaced with the new word "Geek" using the replace() method.
Output:
Example 2: In this example, the input character is getting replaced with the searched character with the help of replace() method.
Output: