Notifications
Clear all

[Closed] Finding lowest number

I have a text file with data formatted like this:


{
	id = 1,
	someData1 = someValue1,
	someData2 = someValue2,
}
{
	id = 355,
	someData1 = someValue1,
}
{
	id = 20,
	someData1 = someValue1,
}
etc...

So there is an id and some other data and they are not in any particular order. I need to create new “block” of properties in that file but I need to find lowest number for id that is not already in use. Any ideas what would be the best way to do that?

4 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

 (
 	ss = openfile @"c:	emp\ids.txt"
 	ids = #{}
 	while not eof ss do
 	(
 		if (skipToString ss "id = ") != undefined do
 		(
 			id = readDelimitedString ss "," 
 			append ids (id as integer)
 		)
 	)
 	close ss
 	lowest = undefined 
 	for k=1 to ids.count while lowest == undefined where not ids[k] do lowest = k 
 	format "lowest available: %
" lowest
 	lowest
 )
 

put values into an array and then just do
amin #() or amax #()

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

not so easy he needs lowest available

Thanks denisT!