Hi Guys,
TIP SPEL: How to transform a string of values into an array without using the split function?
Just use the spell_object method as shown below.
My first post here... :)
Enjoy.
void zSplitString(...)
{
int zi_debug;
string zs_method, zs_str, zs_value, zs_delim, zs_regex;
zs_method = is_empty(class()) ? 'zSplitString' : format("%s zSplitString", class());
zs_str = (string) argv[0];
zs_delim = (string) argv[1];
zs_regex = (string) argv[2];
if (argc>3) zi_debug = (int) argv[3];
if (is_empty(zs_str)) zs_str = '';
if (is_empty(zs_delim)) zs_delim = ',';
if (is_empty(zs_regex)) zs_regex = '[A-Z]+';
if (zi_debug > 0) {
if (!is_empty(event())) logf(SIGNIFICANT, "%s EVENTO : '%s'", zs_method, event());
logf(SIGNIFICANT, "%s ENTRADA : '%s'", zs_method, zs_str);
logf(SIGNIFICANT, "%s DELIMITADOR: '%s'", zs_method, zs_delim);
logf(SIGNIFICANT, "%s REGEX : '%s'", zs_method, zs_regex);
if (!is_empty(this)) logf(SIGNIFICANT, "%s OBJETO : '%s'", zs_method, (string) this);
}
int zi_idx, zi_idx_start, zi_idx_end;
zi_idx = 0;
zi_idx_start = sindex(zs_str, zs_regex, 0);
zi_idx_end = sindex(zs_str, zs_delim, zi_idx_start+1);
if (zi_idx_end == -1) zi_idx_end = strlen(zs_str);
if (zi_debug > 0) logf(SIGNIFICANT, "%s Retornando valores...", zs_method);
do {
zs_value = substr(zs_str, zi_idx_start, zi_idx_end-zi_idx_start);
if (zi_debug > 0) logf(SIGNIFICANT, "%s msg[%d] : '%s'", zs_method, zi_idx, zs_value);
set_return_data(zi_idx++, zs_value);
zi_idx_start = sindex(zs_str, zs_regex, zi_idx_end+1);
zi_idx_end = sindex(zs_str, zs_delim, zi_idx_start+1);
if (zi_idx_end == -1) zi_idx_end = strlen(zs_str);
} while (zi_idx_start > -1);
if (zi_debug > 0) logf(SIGNIFICANT, "%s SAIDA : Array de %d posicoes", zs_method, zi_idx);
}
void zSplitStringSample()
{
int zi_i, zi_debug;
string zs_method;
zs_method = 'zSplitStringSample';
zi_debug = 1;
string zs_str, zs_delim, zs_regex;
zs_str = 'NOME;ENDEREÇO;TELEFONE';
zs_delim = ';';
zs_regex = '[aA0-zZ9]+';
if (zi_debug > 0) logf(SIGNIFICANT, "%s Encaminhando string de valores ao metodo 'zSplitString'...", zs_method);
send_wait(0, spell_object(),
"zSplitString",
(string) zs_method,
(string)'PARSER',
(object) NULL,
(string) zs_str,
(string) zs_delim,
(string) zs_regex,
(int) zi_debug
);
if (zi_debug > 0) logf(SIGNIFICANT, "%s Valores recebidos: %d", zs_method, msg_length());
for (zi_i=0;zi_i<msg_length();zi_i++) {
logf(SIGNIFICANT, "%s #%d: '%s'\n", zs_method, zi_i, (string) msg[zi_i]);
}
}
------------------------------
CA Service Desk Manager Especialist Developer
https://www.facebook.com/groups/usuariossdmbrasil/------------------------------