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
#37955 - 12/05/11 03:53 PM split Variable Address String from one line
Ziggy Offline
OL Newbie

Registered: 11/29/11
Posts: 8
I have an address line that is separated by comma's

eg.

Street #,Street Name,City, Prov, Country, Postal

I'm new to this but I figured it would require Planet Press Talk? I am not sure what combination of functions might work.

I need Find the positions of the comma's... including the instance, so it might require a loop? I just wasn't sure if there is a specific function that could split a string into Parts based on a separator?

I tried the basic "Find" function but it appeared to see the comma (wrapped in single quotes) as a separator of the function... I know this function won't work as it is.... just testing the syntax as I am still trying to learn the functionality of the "Talk".

Thanks

Ziggy

Top
#37960 - 12/06/11 10:02 AM Re: split Variable Address String from one line [Re: Ziggy]
Raphael Lalonde Lefebvre Offline
OL Expert

Registered: 10/14/05
Posts: 4956
Loc: Objectif Lune Montreal
Ziggy,

If we just wanted to display each values on it's own line, then a simple "search" loop would be enough. However, in this case, we may want some values to be on the same line, and we need to be able to format them more freely.

For this case, here's a function that I've made that could help you:

Code:
function @ExtractData(&line:integer, &fieldnum:integer):string
  % Function to extract data from fields of a csv file. (or any comma delimited files)
  % Made by: Raphaël Lalonde Lefebvre, Objectif Lune

  % Note that this function is not part of an official solution, and is not supported
  % by Objectif Lune. Use this function at your own risks.
  define(&i, integer, 0)
  define(&pos, integer, 1)
  define(&curstr, string, '')
  define(&curline, string, '')
  define(&inquotes, boolean, false)
  define(&j, integer, 0)

  &curline := @(&line, 1, 1000)

  for(&j, 1, 1, 100)
    &curline := stringreplace(&curline, ',,', ', ,')
  endfor()

  repeat
    &curstr := ''
    repeat
      &curstr := &curstr + mid(&curline, &pos, 1)
      if(mid(&curline, &pos, 1) = '"')
        if(&inquotes)
          &inquotes := False
        elseif()
          &inquotes := True
        endif()
      endif()
      &pos := &pos + 1
    until(((mid(&curline, &pos, 1) = ',') or (&pos > length(&curline))) and (not(&inquotes)))
    &i := &i + 1
    &pos := &pos + 1
  until(&i = &fieldnum)

  &Result := stringreplace(&curstr, '"', '')
endfunction()



This function looks at a specific line, and returns the value of a "field". It was originally made for using CSV files in line printer emulation, but it can be used in non-CSV files that still have values separated by commas.

The function has two parameters. The first one is the line where the comma-separated values are found. The second one is which value you want. So as a an example, let's assume you have your line of data on data line 3. Knowing this, if you called the function with these parameters:

@ExtractData(3, 2)

It would return the "second field", in other words, Street Name. If you used this instead:

@ExtractData(3, 5)

It would return Country.

So you could make a text box with some custom variables, and then have each variables make a call to the function. You'll be able to either put a value on each lines, or multiple values on the same line, as you need.

Hope that helps!

Regards,
Raphaël Lalonde Lefebvre


Edited by Raphael Lalonde Lefebvre (12/06/11 10:03 AM)

Top
#37961 - 12/06/11 10:33 AM Re: split Variable Address String from one line [Re: Raphael Lalonde Lefebvre]
Ziggy Offline
OL Newbie

Registered: 11/29/11
Posts: 8
Thank you very much Raphael, I look forward to trying this shortly. I will let you know how it goes.

The logic sounds like what I am looking for, I Used Monarch sofware in the past and it has functions that let you define a separator and how many "Parts" the string contains... then you specify which part to return.

Top
#37978 - 12/07/11 09:46 AM Re: split Variable Address String from one line [Re: Ziggy]
Ziggy Offline
OL Newbie

Registered: 11/29/11
Posts: 8
My document is working great, thanks for the help.

For any other newbies (like me) wondering where to put the code..

I used the "Press Talk" button then pasted the above code in the "Planet Press Talk code" section ( the dialogue that comes up).... click ok, and I named the object "Extractfunction" (for visual reference)... Note that this is within the Page itself
NOte I also modified the reference slightly because I wanted to capture the data starting/ending at a certain point in the line.

from:

Code:
 &curline := @(&line, 1, 1000)


to:

Code:
 &curline := @(&line, 14, 91)



then I added another "PressTalk" and this is the one that will show the data...

I put...

Code:
showleft(trim(@ExtractData(26, 1)))


which refers to the 26 line on my report and the 1st position (field) of the comma separated line., change the 1 to refer to subsequent fields in additioanl "Press Talk" fields to get the other references.


That's how I did it, I am sure there might be other variations that will work



Edited by Ziggy (12/07/11 09:59 AM)

Top