Notifications
Clear all

[Closed] findstring arrays

I’m trying to break following string into arrays and trying ‘findstring’.

[1] C: [2] Local Fixed Disk [3] DRIVE_C [4] [Used: 75682111488] [Free: 61745831936] [Total: 137427943424] [8]

Findstring only allows to break string for each character so using this doesn’t work.
filterString HD_temp “[1] [2] [3] [4] [8]”

Is there another way to break string into array by using token for string phrase rather than character?

2 Replies

This should help you get going

(
	HD_temp = "[1] C: [2] Local Fixed Disk [3] DRIVE_C [4] [Used: 75682111488] [Free: 61745831936] [Total: 137427943424] [8]"
	locOfHeaders = #()
	data = #()
	dataHeaders = #("[1]","[2]","[3]","[4]")
	for dataHeader in dataHeaders do
	(
		headerLoc = findString HD_temp dataHeader 
		append locOfHeaders headerLoc 
	)
	for i = 1 to locOfHeaders.count do
	(
		if i !=  locOfHeaders.count then
		(
			append data (substring HD_temp (locOfHeaders[i]+dataHeaders[i].count+1) ((locOfHeaders[i+1])-(locOfHeaders[i]+dataHeaders[i].count+2)))
		)
		else 
		(
			append data (substring HD_temp (locOfHeaders[i]+dataHeaders[i].count+1) ((HD_temp.count)-(locOfHeaders[i])))
		)
	)
	for i = 1 to data.count do
	(
		print data[i]
	)
)

Thanks. That worked.