是否有任何 powerbuilder 功能相当于 PHP 的“爆炸”功能?功能

发布于 2024-09-07 18:53:35 字数 192 浏览 3 评论 0原文

我认为标题本身是不言自明的。 powerbuilder中有没有相当于PHP的“explode”功能的函数?

对于 PHP 的“explode”,请参阅以下链接:PHP Explode

I think the title itself is pretty self-explanatory. Is there any function in powerbuilder which is equivalent to PHP's "explode" function?

For PHP's "explode", see the following link : PHP explode

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

℉絮湮 2024-09-14 18:53:38

Powerbuilder 几乎专门用于数据库密集型应用程序,为此使用您的数据库系统可能更方便。

如果您使用的是 Sybase SQL Anywhere(其运行时随 Powerbuilder 一起提供),则可以使用 sa_split_list 系统过程

或者您可以构建自己的。 PFC 包含您可以使用的此功能

//////////////////////////////////////////////////////////////////////////////
//
//  Function:  of_ParseToArray
//
//  Access:  public
//
//  Arguments:
//  as_Source   The string to parse.
//  as_Delimiter   The delimeter string.
//  as_Array[]   The array to be filled with the parsed strings, passed by reference.
//
//  Returns:  long
//  The number of elements in the array.
//  If as_Source or as_Delimeter is NULL, function returns NULL.
//
//  Description:  Parse a string into array elements using a delimeter string.
//
//////////////////////////////////////////////////////////////////////////////
//
//  Revision History
//
//  Version
//  5.0   Initial version
//  5.0.02   Fixed problem when delimiter is last character of string.

//     Ref array and return code gave incorrect results.
//
//////////////////////////////////////////////////////////////////////////////
//
/*
 * Open Source PowerBuilder Foundation Class Libraries
 *
 * Copyright (c) 2004-2005, All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted in accordance with the GNU Lesser General
 * Public License Version 2.1, February 1999
 *
 * http://www.gnu.org/copyleft/lesser.html
 *
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals and was originally based on software copyright (c) 
 * 1996-2004 Sybase, Inc. http://www.sybase.com.  For more
 * information on the Open Source PowerBuilder Foundation Class
 * Libraries see http://pfc.codexchange.sybase.com
*/
//
//////////////////////////////////////////////////////////////////////////////

long        ll_DelLen, ll_Pos, ll_Count, ll_Start, ll_Length
string  ls_holder

//Check for NULL
IF IsNull(as_source) or IsNull(as_delimiter) Then
    long ll_null
    SetNull(ll_null)
    Return ll_null
End If

//Check for at leat one entry
If Trim (as_source) = '' Then
    Return 0
End If

//Get the length of the delimeter
ll_DelLen = Len(as_Delimiter)

ll_Pos =  Pos(Upper(as_source), Upper(as_Delimiter))

//Only one entry was found
if ll_Pos = 0 then
    as_Array[1] = as_source
    return 1
end if

//More than one entry was found - loop to get all of them
ll_Count = 0
ll_Start = 1
Do While ll_Pos > 0

    //Set current entry
    ll_Length = ll_Pos - ll_Start
    ls_holder = Mid (as_source, ll_start, ll_length)

    // Update array and counter
    ll_Count ++
    as_Array[ll_Count] = ls_holder

    //Set the new starting position
    ll_Start = ll_Pos + ll_DelLen

    ll_Pos =  Pos(Upper(as_source), Upper(as_Delimiter), ll_Start)
Loop

//Set last entry
ls_holder = Mid (as_source, ll_start, Len (as_source))

// Update array and counter if necessary
if Len (ls_holder) > 0 then
    ll_count++
    as_Array[ll_Count] = ls_holder
end if

//Return the number of entries found
Return ll_Count

Powerbuilder being used almost exclusively for database-intensive applications, it may be more expedient to use your database system for that.

If you're using Sybase SQL Anywhere, a runtime of which ships with Powerbuilder, you could use the sa_split_list system procedure

Or you can build your own. The PFC includes this function you could use

//////////////////////////////////////////////////////////////////////////////
//
//  Function:  of_ParseToArray
//
//  Access:  public
//
//  Arguments:
//  as_Source   The string to parse.
//  as_Delimiter   The delimeter string.
//  as_Array[]   The array to be filled with the parsed strings, passed by reference.
//
//  Returns:  long
//  The number of elements in the array.
//  If as_Source or as_Delimeter is NULL, function returns NULL.
//
//  Description:  Parse a string into array elements using a delimeter string.
//
//////////////////////////////////////////////////////////////////////////////
//
//  Revision History
//
//  Version
//  5.0   Initial version
//  5.0.02   Fixed problem when delimiter is last character of string.

//     Ref array and return code gave incorrect results.
//
//////////////////////////////////////////////////////////////////////////////
//
/*
 * Open Source PowerBuilder Foundation Class Libraries
 *
 * Copyright (c) 2004-2005, All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted in accordance with the GNU Lesser General
 * Public License Version 2.1, February 1999
 *
 * http://www.gnu.org/copyleft/lesser.html
 *
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals and was originally based on software copyright (c) 
 * 1996-2004 Sybase, Inc. http://www.sybase.com.  For more
 * information on the Open Source PowerBuilder Foundation Class
 * Libraries see http://pfc.codexchange.sybase.com
*/
//
//////////////////////////////////////////////////////////////////////////////

long        ll_DelLen, ll_Pos, ll_Count, ll_Start, ll_Length
string  ls_holder

//Check for NULL
IF IsNull(as_source) or IsNull(as_delimiter) Then
    long ll_null
    SetNull(ll_null)
    Return ll_null
End If

//Check for at leat one entry
If Trim (as_source) = '' Then
    Return 0
End If

//Get the length of the delimeter
ll_DelLen = Len(as_Delimiter)

ll_Pos =  Pos(Upper(as_source), Upper(as_Delimiter))

//Only one entry was found
if ll_Pos = 0 then
    as_Array[1] = as_source
    return 1
end if

//More than one entry was found - loop to get all of them
ll_Count = 0
ll_Start = 1
Do While ll_Pos > 0

    //Set current entry
    ll_Length = ll_Pos - ll_Start
    ls_holder = Mid (as_source, ll_start, ll_length)

    // Update array and counter
    ll_Count ++
    as_Array[ll_Count] = ls_holder

    //Set the new starting position
    ll_Start = ll_Pos + ll_DelLen

    ll_Pos =  Pos(Upper(as_source), Upper(as_Delimiter), ll_Start)
Loop

//Set last entry
ls_holder = Mid (as_source, ll_start, Len (as_source))

// Update array and counter if necessary
if Len (ls_holder) > 0 then
    ll_count++
    as_Array[ll_Count] = ls_holder
end if

//Return the number of entries found
Return ll_Count
怪我入戏太深 2024-09-14 18:53:37

不是内置的,但 PFC 字符串服务具有 of_parse_to_array(),它与 PHP 的 explode() 执行相同的操作,除了 limit 之外。如果您不使用 PFC,则可以直接提升 of_parse_to_array() (当然,保留版权声明),或者您可以获取 pfc_n_base、n_base、pfc_n_cst_string 和 n_cst_string 并获得整个字符串服务。如果您确实需要 limit,可以轻松添加实现 limitof_parse_to_array() 重载版本。

Not built-in but the PFC String Service has of_parse_to_array() which does the same thing as PHP's explode(), except for limit. If you're not using PFC you could just lift of_parse_to_array() (keeping the copyright notice, of course), or you could grab pfc_n_base, n_base, pfc_n_cst_string, and n_cst_string and have the whole string service. If you really need limit, it's easy to add an overloaded version of of_parse_to_array() that implements limit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文