Substitute and Replace functions in PeopleCode

 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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值