我有线
'TEST1, TEST2, TEST3'我想要
'TEST1,TEST2,TEST3'是不是在powerbuilder中是一个像替换,substr之类的函数?
发布于 2012-09-25 07:45:09
一种方法是使用数据库,因为您可能有一个活动的连接。
string ls_stringwithspaces = "String String String String"
string ls_stringwithnospace = ""
string ls_sql = "SELECT replace('" + ls_stringwithspaces + "', ' ', '')"
DECLARE db DYNAMIC CURSOR FOR SQLSA;
PREPARE SQLSA FROM :ls_sql USING SQLCA;
OPEN DYNAMIC db;
IF SQLCA.SQLCode > 0 THEN
// erro handling
END IF
FETCH db INTO :ls_stringwithnospace;
CLOSE db;
MessageBox("", ls_stringwithnospace)发布于 2012-09-24 20:29:30
当然有(你可以很容易地在帮助中找到它),但它并不是很有帮助。
它的原型是Replace ( string1, start, n, string2 ),因此在调用它之前,您需要知道要替换的字符串的位置。
对此有一个通用的包装器,它由pos() / replace()上的循环组成,直到没有任何东西可替换。下面是一个全局函数的源代码:
global type replaceall from function_object
end type
forward prototypes
global function string replaceall (string as_source, string as_pattern, string as_replace)
end prototypes
global function string replaceall (string as_source, string as_pattern, string as_replace);//replace all occurences of as_pattern in as_source by as_replace
string ls_target
long i, j
ls_target=""
i = 1
j = 1
do
i = pos( as_source, as_pattern, j )
if i>0 then
ls_target += mid( as_source, j, i - j )
ls_target += as_replace
j = i + len( as_pattern )
else
ls_target += mid( as_source, j )
end if
loop while i>0
return ls_target
end function注意,PB中的字符串函数(搜索和连接)效率不高,另一种解决方案可能是使用PbniRegex扩展提供的FastReplaceall()全局函数。它是一个从版本9到12的PB classic的c++编译插件。
发布于 2012-09-24 21:01:59
我这样做:
long space, ll_a
FOR ll_a = 1 to len(ls_string)
space = pos(ls_string, " ")
IF space > 0 THEN
ls_string= Replace(ls_string, space, 1, "")
END IF
NEXThttps://stackoverflow.com/questions/12564772
复制相似问题