- 论坛徽章:
- 0
|
可以參考ILE PRG Reference中%check的例子。
*..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
*--------------------------------------------------
* A string contains a series of numbers separated
* by blanks and/or commas.
* Use %CHECK to extract the numbers
*--------------------------------------------------
D string s 50a varying
D inz('12,233 17,1,234')
D delimiters C ' ,'
D digits C '0123456789'
D num S 50a varying
D pos S 10i 0
D len S 10i 0
D token s 50a varying
/free
// make sure the string ends with a delimiter
string = string + delimiters;
dou string = '';
// Find the beginning of the group of digits
pos = %check (delimiters : string);
if (pos = 0);
leave;
endif;
// skip past the delimiters
string = %subst(string : pos);
// Find the length of the group of digits
len = %check (digits : string) - 1;
// Extract the group of digits
token = %subst(string : 1 : len);
dsply ' ' ' ' token;
// Skip past the digits
if (len < %len(string));
string = %subst (string : len + 1);
endif;
enddo;
/end-free |
|