Many of the peoplesoft developers would be knowing these function, but for others I just want to say my friends these are really very nice delivered functions in peoplecode used for string manipulation.
If we want to replace some text by some other text wherever it repeats in a string, we use substitute function and if we want to replace the text in a string by some other text with the start and end position given, we use replace function. Don't you think it's pretty confusing??? If So, I think you are now prepared to read this article.
We will try to understand this concept using examples here. Ok, let there is some string &str_test defined in peoplecode as:
&str_test = "He always helps others. He is a good boy.";
Now I need to change the word "He" in string by some name let us say "John", then here function substitute() can be of our help and syntex will be:
&str_test = Substitute(&str_test, "He", "John");
Now as we have used the substitute function, the new value of &str_test will be:
"John always helps others. John is a good boy."
Now for understanding the replace function, let us take the example of credit card number. Credit card number of a user is taken in a string variable as:
&Card_num = "1234123412345678";
If somewhere in my application I want to show only last 4 digits of credit card number to users on page (for some security purpose or anything else), then in this case we will use replace function as:
&Card_num = Replace(&Card_num, 1, 12, "XXXX-XXXX-XXXX-");
Here we have given start and end position of text to be replaced and the string which will replace them as parameters here and output value of &Card_num will look like:
"XXXX-XXXX-XXXX-5678"
Replace and Substitute were really confusing to me when I read them initially but after I used them one or two times, I was able to explain them to you. Hope it was of any help to you....Thanks
If we want to replace some text by some other text wherever it repeats in a string, we use substitute function and if we want to replace the text in a string by some other text with the start and end position given, we use replace function. Don't you think it's pretty confusing??? If So, I think you are now prepared to read this article.
We will try to understand this concept using examples here. Ok, let there is some string &str_test defined in peoplecode as:
&str_test = "He always helps others. He is a good boy.";
Now I need to change the word "He" in string by some name let us say "John", then here function substitute() can be of our help and syntex will be:
&str_test = Substitute(&str_test, "He", "John");
Now as we have used the substitute function, the new value of &str_test will be:
"John always helps others. John is a good boy."
Now for understanding the replace function, let us take the example of credit card number. Credit card number of a user is taken in a string variable as:
&Card_num = "1234123412345678";
If somewhere in my application I want to show only last 4 digits of credit card number to users on page (for some security purpose or anything else), then in this case we will use replace function as:
&Card_num = Replace(&Card_num, 1, 12, "XXXX-XXXX-XXXX-");
Here we have given start and end position of text to be replaced and the string which will replace them as parameters here and output value of &Card_num will look like:
"XXXX-XXXX-XXXX-5678"
Replace and Substitute were really confusing to me when I read them initially but after I used them one or two times, I was able to explain them to you. Hope it was of any help to you....Thanks