IMPORTANT ANNOUNCEMENT

These forums were permanently set to read-only mode on July 20, 2022. From that day onwards, no new posting or comment is allowed on the site, but the historical content remains intact and searchable.

A new location for posting questions about PlanetPress Suite is now available:

OL Learn - PlanetPress Classic (opens in new tab)

Topic Options
#55959 - 05/09/18 04:37 AM How to extract variable fields in text data ??
Andy1974 Offline
OL Guru

Registered: 03/26/08
Posts: 126
Loc: Hong Kong
Hello everyone,

I'm now prepare a customer report template by planetpress design. And I need to read a customer statistic text data
and then extract some fields in the template.

However, in line 2 of the data, it contains four fields, they are company name, company code, salesman code and salesman name and these fields are not in fixed position.

My problem is how to extract these four fields correctly ?
I can't specific the fixed position in design because they're all in variable length.

I need to extract them correctly and set them into the specified position in template.

I think it can be solved by planetpress talk code, but I'm not too familiar on this coding.

Do anyone can help me to solve my problem ?

Below example of customer statistic text data.

Remarks : x mean the space.

Data 1, line 2 :
----------------
xxxxxxTOPPANxAxCOMPANYxLTDxxxxxxxSDC101xxxxxA12345MxxxxPETER CHAN

Data 2, line 2 :
----------------
xxxxEPLxPAPERxCOMPANYxLIMITEDxxxxxSDC102xxxB12345MxxxJOHNSONxWU

Data 3, line 2 :
----------------
xxxxxxxHOTTOPxCOMPANYxLTDxxxxxSDC103xxxC12345MxxxxFELIXxLAI


Many thanks !

Best Regards,
Andy...

Top
#55960 - 05/09/18 04:19 PM Re: How to extract variable fields in text data ?? [Re: Andy1974]
Philippe F. Offline
OL Expert

Registered: 09/06/00
Posts: 1984
Loc: Objectif Lune, Montreal, Qc
Well that doesn't leave us much to work with...

Looking at your mock data, it appears the only consistent information we can use is the fact that whenever there are 2 or more whitespace characters in the data, we can infer that we are "in-between" fields.

Using that information, we can write code like the following (the first line is using hard-coded data, you should replace that with an actual data selection):
Code:
define(&data,string,trim('      TOPPAN A COMPANY LTD       SDC101     A12345M    PETER CHAN'))
define(&i,integer,0)
define(&array,arraystring,['','','',''])
define(&arrayIndex,integer,0)
define(&inField,boolean,true)
for(&i,0,1,length(&data))
   if(mid(&data,&i,2)='  ')
      if(&inField)
         &arrayIndex := &arrayIndex+1
         &inField := false
      endif()
   else
      &array[&arrayIndex] := &array[&arrayIndex]+mid(&data,&i,1)
      &infield := true
   endif()
endfor()

define(&CompanyName,string,trim(&array[0]))
define(&CompanyCode,string,trim(&array[1]))
define(&SalesmanCode,string,trim(&array[2]))
define(&SalesmanName,string,trim(&array[3]))

show('Company name:  '+&CompanyName)
crlf()
show('Company code:  '+&CompanyCode)
crlf()
show('Salesman code: '+&SalesmanCode)
crlf()
show('Salesman name: '+&SalesmanName)
crlf()

Note, however, that if any of the fields contains a sequence of two spaces or more, then the above code won't work.
_________________________
Technical Product Manager
I don't want to achieve immortality through my work; I want to achieve immortality through not dying - Woody Allen

Top
#55961 - 05/09/18 04:46 PM Re: How to extract variable fields in text data ?? [Re: Andy1974]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 681
Loc: Québec, Canada
Another approach would be to do a script in Workflow, prior to the form , in which you would replace the line where you have the x-axis "mobile" text line and using Regex, replace that line with something like this:

TOPPAN A COMPANY LTD|SDC101|A12345M|PETER CHAN
EPL PAPER COMPANY LIMITED|SDC102|B12345M|JOHNSON WU
HOTTOP COMPANY LTD|SDC103|C12345M|FELIX LAI

Using the '|' delimiter, you could more easily extract the value you need using the Search/End Search PressTalk procedure.

Like this:

margin(0,0.1667)
define(&theString,string,'EPL PAPER COMPANY LIMITED|SDC102|B12345M|JOHNSON WU')

Search(&theString,'|')
show(&theString)
crlf(0.1667)
endSearch()

show(&theString)
_________________________
♪♫♪♫
99 frigging bugs in my code
99 frigging bugs
Take one down
Code around
127 frigging bugs in my code
♪♫♪♫

Top
#55964 - 05/10/18 10:49 PM Re: How to extract variable fields in text data ?? [Re: Andy1974]
Andy1974 Offline
OL Guru

Registered: 03/26/08
Posts: 126
Loc: Hong Kong
Dear Mr. Philippe and Mr. Jean,

Many thanks your both suggestions on my questions, and I'll
try them to see whether the result is ok or not

Best Regards,
Andy...

Top