1. Andrew Davis
  2. PowerBuilder
  3. Monday, 19 June 2023 16:01 PM UTC

Hi

I have a textfile which is formatted like below code then tab then size - size is a list of sizes separated by a comma but could be 1 or 20 values.

code <tab> size

AP01<tab>12,14,16,18,20

TR01<tab>28,30,32,34,36,38,40,42

what is the best way to extract the sizes from the text is there a way to fill an array with these values for example

 

any help would be much appreciated 

 

regards

Andrew

 

 

Miguel Leeuwe Accepted Answer Pending Moderation
  1. Monday, 19 June 2023 17:23 PM UTC
  2. PowerBuilder
  3. # 1

Hi,

I would try to:

1. Read all of the file contents using FileReadEx or if you prefer FileRead line by line

2. Convert the obtained blob into a string and  replace all of the commas with a TAB character ("~t")

3. Create an external datawindow with a field "code" of type char(4) and 19 other fields "value01, value02, ...... value18, value19 of type number.

4. Use ImportString() to import the string into your datastore / datawindow (or first write everything to a file and then use ImportFile() ).

regards.

 

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 19 June 2023 19:57 PM UTC
  2. PowerBuilder
  3. # 2

Hi Andrew;

  FWIW: I would create an external Datawindow with columns to match your CSV fields & then simply use the ImportFile() command. Quick & simple IMHO.

HTH

Regards ... Chris 

Comment
  1. Chris Pollach @Appeon
  2. Monday, 19 June 2023 20:32 PM UTC
Hi John;

No, you would need a DW PowerScripr loop to clean that up that 1st column. Your idea though to write the data to a CSV file while replacing the "tab" with a comma would also be another great approach.

Regards ... Chris
  1. Helpful
  1. Miguel Leeuwe
  2. Monday, 19 June 2023 21:54 PM UTC
I don't know, but this is exactly what I already answered below.
  1. Helpful
  1. John Fauss
  2. Tuesday, 20 June 2023 02:53 AM UTC
I concur, Miguel.
  1. Helpful 1
There are no comments made yet.
Benjamin Gaesslein Accepted Answer Pending Moderation
  1. Tuesday, 20 June 2023 08:20 AM UTC
  2. PowerBuilder
  3. # 3

Hi Andrew,

if all you need is an array, you can borrow the of_parsetoarray function from the PFC string helper class, it splits a string into an array with a given delimiter. Just look for the tab character for each line with Pos() and remove the left part first.

This will create a string array; if you need a number array instead, you should be able to easily adapt the function to convert each value to a number first.

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.