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

时间:2010-06-30 07:33:25

标签: powerbuilder powerbuilder-pfc

我认为标题本身是不言自明的。 powerbuilder中是否有任何功能相当于PHP的“爆炸”功能?

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

2 个答案:

答案 0 :(得分:3)

不是内置的,但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 ,则可以轻松添加实现 limit of_parse_to_array()的重载版本。

答案 1 :(得分:3)

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

如果您使用的是运行时随Powerbuilder一起提供的Sybase SQL Anywhere,则可以使用sa_split_list system procedure

或者你可以建立自己的。 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