Stuff Vs. Replace Vs. Substring
Stuff:
Using the stuff function we can remove a substring of a certain length of a string and replace it with a new string.
Refer the following arguments that we need to pass to the Stuff function:
Refer the following arguments that we need to pass to the Stuff function:
First argument passed to the function is the expression. Second argument is the starting length from where the new characters are to be added. Third argument tells how many characters to allocate to the new string being embedded. Fourth argument takes the new string to be embedded as a parameter.
Let us run this and check the output.
We will now add some characters to this string. See the following Stuff function.
It will insert “!!” at the end of the expression. Let us check the output.
Replace:
As the function name replace indicates, the replace function replaces all occurrences of a specific string value with another string.
Refer the following arguments that we need to pass to the Replace function:
The replace function takes the expression as the first parameter. Second parameter is the string present in the expression that is to be replaced. The third parameter is the string that will replace the second parameter in the function.
We will replace few characters in this expression using Replace function.
Substring:
Using Substring function we get a specific portion of the expression.
Refer the following arguments that we need to pass to the Stuff function:
The first parameter Substring function takes is the expression. Second parameter is the starting position of the expression which takes integer as input and the third parameter is the length which means the characters till this length from the starting position of the second parameter will be returned from the expression.
Let us execute the following commands.
We get the preceding result using Substring function.
Comments
Post a Comment