I’m haing a problem tokenizing a flat file using the webMethods services.
The file contains a number of fields (some may be empty):
field0| field1| field2||field4|||field7
I would expect pub.string:tokenize to give me a list as (when tokenizing by |):
0 field0
1 field1
2 field2
3 null or blank
4 field4
5 null or blank
6 null or blank
7 field5
However, it is skipping the null values to give me:
0 field0
1 field1
2 field2
3 field4
4 field5
I considered using pub.string:replace to replace all “||” with “| |”, but I also need to check for “|||”, “||||”, etc. I am having difficulty using a regex search to solve this problem.
Hello,
Your issue starts with the fact that string:tokenize that you use is probably based on the Java StringTokenizer class which does the same annoying thing. I have a simple tokenize flow service. 100% flow using only WM flows in transformers.
Do a pub.string:replace, then do a Repeat, checking for pub.string:indexOf (substring = “||”). Do a branch, and break from the loop if %value% == -1. The $default branch of the loop is another pub.string:replace.