首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从spaces powerbuilder中清除字符串

从spaces powerbuilder中清除字符串
EN

Stack Overflow用户
提问于 2012-09-24 20:07:21
回答 3查看 5K关注 0票数 0

我有线

代码语言:javascript
复制
'TEST1, TEST2, TEST3'

我想要

代码语言:javascript
复制
'TEST1,TEST2,TEST3'

是不是在powerbuilder中是一个像替换,substr之类的函数?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-09-25 07:45:09

一种方法是使用数据库,因为您可能有一个活动的连接。

代码语言:javascript
复制
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)
票数 2
EN

Stack Overflow用户

发布于 2012-09-24 20:29:30

当然有(你可以很容易地在帮助中找到它),但它并不是很有帮助。

它的原型是Replace ( string1, start, n, string2 ),因此在调用它之前,您需要知道要替换的字符串的位置。

对此有一个通用的包装器,它由pos() / replace()上的循环组成,直到没有任何东西可替换。下面是一个全局函数的源代码:

代码语言:javascript
复制
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++编译插件。

票数 2
EN

Stack Overflow用户

发布于 2012-09-24 21:01:59

我这样做:

代码语言:javascript
复制
  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
     NEXT
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12564772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档