Gateway Script How to use split, numberFormat, tofloat?

Hello,
I currently have an expression tag that is garbing specific information from a comma delimited string.
The expression of the tag is too long and prevents a gateway script from using the correct value, I need to do conversion withing the gateway script.

What libraries do I need to expose to be able to do the following?
numberFormat(tofloat(split({[.]CheeseScale},",")[2,0],0),"#0.00")

right now I’m getting.

Traceback (most recent call last):
File “TagChangeScript:Farmdale/CheeseScaleScript”, line 29, in
NameError: name ‘split’ is not defined
NameError: name ‘numberFormat’ is not defined.
NameError: name ‘tofloat’ is not defined.

1 Like

At the moment it looks like your trying to use a mix of python and expression languages…

Can we get a sample of what the data coming in would look like?

Here is the string.
3,158,42.80,2163.70,2,1,CH001BK,20150304

so the value will always be the third item?

Yes

Gotcha. I’m on my way home, but should have something for you later on this evening. :slight_smile:

My connection back to work is flaky tonight, but QPython on my Kindle to the rescue!
Here’s a python example that should give you some ideas.

[code]def find_nth_character(str1, substr, n):
pos = -1
for x in xrange(n):
pos = str1.find(substr, pos+1)
if pos == -1:
return None
return pos

dataIn=‘3,158,42.80,2163.70,2,1,CH001BK,20150304’
subStart = find_nth_character(dataIn,’,’,2) + 1
subEnd = find_nth_character(dataIn,’,’,3)

print dataIn[subStart:subEnd][/code]


1 Like

Thank you Jordan,
I wanted to use the build in function of python within the gateway script and here is the approached I’m taking

==============
import string
strDataIn=‘3,158,42.80,2163.70,2,1,CH001BK,20150304’
strDataOut = string.split(strDataIn,",")[2:3]
strWeight = string.join(strDataOut)

once gain thank you.

1 Like