Jack
Jack

Reputation: 1437

Netlogo - add one more digit to the string automatically

I am modelling a warehouse. each cell has been assigned to a id in a format like below.

enter image description here

The standard format of the external data is four digits. However, there are some ids which are only 3 like "A05". Is there a easy way to automatically add one more "0' to make it like "A005"?

Upvotes: 0

Views: 54

Answers (1)

Luke C
Luke C

Reputation: 10301

Maybe this reporter will work for you- it should just add a zero in the second position until the string length is 4 or greater.

to setup
  ca
  print map add-zero [ "A" "A1" "A01" "A001" "A123" ] 
  reset-ticks
end

to-report add-zero [ string ]
  if length string >= 4 [
    report string
  ]
  report add-zero insert-item 1 string "0"  
end

Upvotes: 1

Related Questions