2010-06-30 3 views
1

Je pense que le titre lui-même est assez explicite. Y at-il fonction PowerBuilder ce qui équivaut à la fonction « exploser » PHP?Y at-il fonction de PowerBuilder ce qui équivaut à la fonction « Explode » de PHP

Pour « exploser », voir le lien suivant de PHP: PHP explode

+0

[question similaire] (http://groups.google.com/group/sybase.public.powerbuilder.powerscript/browse_thread/thread/379c3c2af8bd968f/0b2bde1bea45ee96?lnk=raot&pli = 1) sur sybase.public.powerbuilder.powerscript – Sjoerd

Répondre

3

Non intégré, mais le service chaîne PFC a of_parse_to_array() qui fait la même chose que de explode() PHP, sauf pour limite. Si vous ne l'utilisez PFC vous pouvez simplement soulever of_parse_to_array() (en gardant l'avis du droit d'auteur, bien sûr), ou vous pouvez saisir pfc_n_base, n_base, pfc_n_cst_string et n_cst_string et ont l'ensemble du service de chaîne. Si vous avez vraiment besoin limite, il est facile d'ajouter une version surchargée de of_parse_to_array() qui implémente limite.

+0

_limit_ serait utile si vous attendiez la chaîne à analyser en plusieurs jetons, mais vous étiez seulement intéressé par la première _n_. –

3

Powerbuilder utilisé presque exclusivement pour les applications de base de données à forte intensité, il peut être plus avantageux d'utiliser votre système de base de données pour cela.

Si vous utilisez Sybase SQL Anywhere, un moteur d'exécution qui est livré avec Powerbuilder, vous pouvez utiliser le sa_split_list system procedure

Ou vous pouvez construire votre propre. Le PFC comprend cette fonction vous pouvez utiliser

////////////////////////////////////////////////////////////////////////////// 
// 
// 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