Read from File --> LookupTable

Hello,

i need an help

i have to convert some values. If in my input string is “A” i have to convert it in 1, if “B” in 2, “C” in 3 etc etc.
I used the LookUpTable and it works fine.
However i need to put this key/values in a file and then read the file and do the conversion.

How can i solve this problem?

Thank you,

MS

Hi Matteo,

what about using pub.string:lookupDictionary instead of pub.string:lookupTable?
It is using a Hashtable instead of a String-Array.
You can create this Hashtable by using the services from pub.hashtable-Folder after you have read the keys/values from your file.
You can use the services from pub.file-Folder to read in the fiile.

Regards,
Holger

1 Like

Hi Holger,

it’s seems very interesting. Can you please tell me more?
Can i store the hashtable in memory so i don’t have to read every time the configuration file?

Can you please be so kind to show me step by step witch flowservices i have to use?

Thank you

Hi Matteo,

create a flow service to create the hashtable from file.
Define the hashtable as output and set the service to caching enabled.

pub.file:getFile
pub.hashable:createHashtable

Whenever you need access to the hashtable call this service and then use pub.string:lookupDictionary to query the hashtable.

See IS Built-In-Services Guide for further informations.

Regards,
Holger

Hi Holger,

i’m noobie and maybe not able to complete the service

As you can see in the image there is no input for the hashtable. How can i map [/img]the string from getfile and, other question, can you please provide to me an example of a hashtable file?

Sorry but i feel just a bit confused

Holger,

i just updated the post above because the link to the img was broken

Hi Matteo,

most likely your file is some sort of a properties file containig key/value pairs.

You will have to iterate over the pairs and add them to the hashtable using pub.hashtable:put.

Regards,
Holger

I can decide how to build my file.

What is the best format? an xml structure?