【peoplesoft】替换字符串函数Substitute

在peoplecode里想用跟Oracle一样的replace函数,进行字符串替换。

peoplecode里确实也有replace函数,但是这个函数的功能和Oracle的replace还不太一样。

 

我们来看看peoplecode的replace函数,就是直接将某段字符串替换为新字符串,这并不是我想要的。

Replace

Syntax

Replace(oldtext, start, num_chars, newtext)

Description

Use the Replace function to replace a specified number of characters in a string.

Parameters

Field or Control

Definition

oldtext

A String value, part of which is to be replaced.

start

A Number designating the position in oldtext from which to start replacing characters.

num_chars

A Number, specifying how many characters to replace in oldtext.

newtext

A String value that replaces num_chars characters.

Returns

Returns a String value in which specific characters in oldtext are replaced with newtext.

Example

After the following statement &NEWDATESTR equals "1997":

&NEWDATESTR = Replace("1996",3,2,"97");

If this example, where the number of characters in newtext is less than num_chars, &SHORTER equals "txtx":

&SHORTER = Replace("txt123",4,3,"x");

In this example, where the number of characters in newtext is greater than num_chars, &LONGER equals "txtxxxx":

&LONGER = Replace("txt123",4,3,"xxxx");

 

substitue才是我想要的,类似Oracle的replace的函数,用法也类似,将原字符串替换成目标字符串。

 

Substitute

Syntax

Substitute(source_text, old_text, new_text)

Description

Use the Substitute function to replace every occurrence of a substring found in a string with a new substring. To replace text that occurs in a specific location in a text string use the Replace function.

Parameters

Field or Control

Definition

source_text

A String in which you want to replace substrings.

old_text

A String equal to the substring of source_text you want to replace.

A tilde character (~) used in the old_text parameter stands for an arbitrary number of white spaces. For example, the following substitution: Substitute("2003* 0723* * * * ~", "* ~", "~") produces the result 2003~0723~~~~~, not the result 2003* 0723* * * ~.

new_text

A String with which to replace occurrences of old_text in source_text.

Returns

Returns a String resulting from replacing every occurrence of old_text found in source_text with new_text.

Example

The following example changes "Second Annual Conference" to "Third Annual Conference":

&newstr = Substitute("Second Annual Conference","Second","Third");

The next example sets &newstr to "cdcdcd":

&newstr = Substitute("ababab", "ab", "cd");
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值