Page 1 of 1

Field function

Posted: Mon Jun 22, 2009 9:50 am
by dodda
Hello

I have a requirement where i have a string like

A%%%AB%%%DF%%%CE%%%XE%%%AF

i want to get the each string which is delimited by %%%.

I used Field function but it is not giving me the required result.

below are the expecte dresults


Field (InputString,'%%%',1)=A
Field (InputString,'%%%',2)=AB
Field (InputString,'%%%',3)=DF
Field (InputString,'%%%',4)=CE
........
Field (InputString,'%%%',6)=AF

Please help me out

Thanks

Posted: Mon Jun 22, 2009 10:07 am
by nani0907
hello,

could you please elaborate on how you need data with both input and output.

Posted: Mon Jun 22, 2009 10:15 am
by dodda
hello nani

i will be getting a string i.e A%%%AB%%%DF%%%CE%%%XE%%%AF in of the fields from the input sequrntial File. I need to read that string and get the values which ar edelimited by %%%

i.e InputString=A%%%AB%%%DF%%%CE%%%XE%%%AF
outstring1=A
outstiring2=AB
outstiring3=DF
outstiring4=CE
outstiring5=XE
outstiring6=AF


I tried field function its not working. please help me
Thanks

Posted: Mon Jun 22, 2009 11:03 am
by priyadarshikunal
The documentation of field function says:
delimiter evaluates to any character, including field mark, value mark, and subvalue marks. It delimits the start and end of the substring. If delimiter evaluates to more than one character, only the first character is used.
Hence it seems like your logic will not work in this case.

If '%' will not be present in data itself you can use field function after the followin conversion:

Code: Select all

Trim(DSLink.InputColumn,"%","R")
which will replace %%% with %, then your logic will work.


If '%' can be present in data itself you need to replace '%%%' with some strange characters like fieldmarks,value marks, char(10) or something similar. then you need to apply field function.

You may need to use PXEreplace posted by DSGuru2B quite a while ago to do the same.

Posted: Mon Jun 22, 2009 11:11 am
by chulett
The Field() delimiter must be a single character. So either convert all of the occurances of "%%%" down to a single "%" or offset the "field" that you ask for:

Code: Select all

FieldNumber = PositionNumber * 3 - 2
In other words, 1 gets field 1, 2 gets field 4, 3 gets field 7, etc.

Posted: Mon Jun 22, 2009 12:47 pm
by kduke
Replacing %%% with % is on the right track but I would replace with something other than % like char(254).

Posted: Mon Jun 22, 2009 1:16 pm
by chulett
Sure, you could replace it with pretty much anything as long as you can guarantee that it isn't used anywhere in the data. Hence Kim's choice. That or just use my fancy pantsy formula. :wink: