# String split function result

**URL:** <https://forum.inductiveautomation.com/t/string-split-function-result/6153>\
**Category:** Ignition\
**Created:** [April 4, 2013, 8:16am UTC](https://forum.inductiveautomation.com/t/string-split-function-result/6153 "2013-04-04T08:16:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashish007pict](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@ashish007pict](https://forum.inductiveautomation.com/u/ashish007pict)\
**Post date:** [April 4, 2013, 8:16am UTC](https://forum.inductiveautomation.com/t/string-split-function-result/6153/1 "2013-04-04T08:16:56Z")

</div>

how to get array/list row/column count when split functions returns string?

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [April 4, 2013, 4:46pm UTC](https://forum.inductiveautomation.com/t/string-split-function-result/6153/2 "2013-04-04T16:46:21Z")

</div>

Not quite sure what you are asking. The split function in the expression language gives you back a dataset with one column and rows for every item you split on. So if your string is:

Hello;SomethingElse;56.7

and you split on the semi-colon:`split("Hello;SomethingElse;56.7", ";")`you would get a dataset with one column and three rows. You can find out how many rows by doing the following:`len(split("Hello;SomethingElse;56.7", ";"))`You can grab one value out of the dataset like this:`split("Hello;SomethingElse;56.7", ";")[1,0]`That gets the value out of row 1 and column 0 which would be “SomethingElse”.

If you are using the split function in scripting here is an example:`str = "Hello;SomethingElse;56.7"
values = str.split(";")
print len(values) # number of items
print values[1] # gives you back "Something Else"`

---

<div class="post-metadata">

**Author:** ![ashish007pict](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@ashish007pict](https://forum.inductiveautomation.com/u/ashish007pict)\
**Post date:** [April 5, 2013, 5:10am UTC](https://forum.inductiveautomation.com/t/string-split-function-result/6153/3 "2013-04-05T05:10:05Z")

</div>

thanks a lot for the info

---

<div class="post-metadata">

**Author:** ![imt.sebastian.sanche](https://avatars.discourse-cdn.com/v4/letter/i/ecb155/32.png) [@imt.sebastian.sanche](https://forum.inductiveautomation.com/u/imt.sebastian.sanche)\
**Post date:** [July 24, 2023, 7:09pm UTC](https://forum.inductiveautomation.com/t/string-split-function-result/6153/4 "2023-07-24T19:09:53Z")

</div>

Hi Travis, hope you can guide me through my error. I have a script to move data from a string to a list so I can write individual values to memory tags. The code is shown below.

```auto
	#Move currentValue to another tag
	string = currentValue
	
	#Tag Paths to list paths.
	pbadge = "[default]CognexEOLInspection/AD01_Cognex/Badge"
	pcflagr = "[default]CognexEOLInspection/AD01_Cognex/C_FlagRH"
	pcflagl = "[default]CognexEOLInspection/AD01_Cognex/C_FlagLH"
	plogo = "[default]CognexEOLInspection/AD01_Cognex/Logo"
	pstatus = "[default]CognexEOLInspection/AD01_Cognex/Status"
	paths =[pbadge, pcflagl, pcflagr, plogo, pstatus]
			
	#Reverse concatenate
	list = string.split(",")
	badge = list[1]
	cflagr = list[3]
	cflagl = list[5]
	logo = list[7]
	status = list[8]
	values = [badge, cflagl, cflagr, logo, status]	
				
	#Assign values to tags.
	system.tag.writeBlocking(paths, values)

```

Now my problem is that it doesn't run and when I go to the gateway logs it keeps saying

> Subject has no attribute 'split'

Any suggestions?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [July 24, 2023, 7:12pm UTC](https://forum.inductiveautomation.com/t/string-split-function-result/6153/5 "2023-07-24T19:12:43Z")

</div>

1. Don't use list or string as variable names
2. To use split you use it on the string object itself, so it should be `someStringVariable.split(',')

Like

```auto
myString = 'some,thing,here'
result = myString.split(',')
print result

```

prints  
`['some', 'thing', 'here'] `

I guess you do have a `string = currentValue` but I don't think that is the right way to ge tthe currentValue. I think it should be `event.currentValue`? Something is wrong with this line. Also we don't know the context this is running. It looks like a tag change script, but on what sort of tag? If it's an integer tag for instance, then your current value is just going to be the new integer value of the tag, not the path of the tag and split doesn't exist for integers.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 24, 2023, 7:17pm UTC](https://forum.inductiveautomation.com/t/string-split-function-result/6153/6 "2023-07-24T19:17:15Z")

</div>

I'm assuming that this is in a tagChange script, or perhaps something else, since you didn't say.

That said, I suspect that instaed of `currentValue`, what you really want is `currentValue.value`, or some variant depending on context.

I would strongly suggest that you use more meaniful variable names, partcuarly not names that match python built-ins

Just imagine if you needed to use `list()` to create a list later on in this script and recieved an error telling you that list is not callable?

---

<div class="post-metadata">

**Author:** ![imt.sebastian.sanche](https://avatars.discourse-cdn.com/v4/letter/i/ecb155/32.png) [@imt.sebastian.sanche](https://forum.inductiveautomation.com/u/imt.sebastian.sanche)\
**Post date:** [July 24, 2023, 7:20pm UTC](https://forum.inductiveautomation.com/t/string-split-function-result/6153/7 "2023-07-24T19:20:15Z")

</div>

Thank you both. I will work on my variant naming, that said it was a value.change script so yeah I had to add the currentValue.value for it to work. I keep forgetting about it 😅

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 24, 2023, 7:25pm UTC](https://forum.inductiveautomation.com/t/string-split-function-result/6153/8 "2023-07-24T19:25:20Z")

</div>

Also, just because I think this is more readable:

```auto
paths = ["[default]CognexEOLInspection/AD01_Cognex/" + tagName for tagName in ('Badge','C_FlagRH','C_FlagLH','Logo','Status')]

system.tag.writeAsync(paths,[currentValue.value.split(',')[i] for i in (1,3,5,7,8)])

```

Maybe it's just me. 😉
