NetLogo-自动在字符串中再添加一位数字 [英] Netlogo - add one more digit to the string automatically

查看:136
本文介绍了NetLogo-自动在字符串中再添加一位数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为仓库建模.每个单元格都已按照以下格式分配给ID.

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

外部数据的标准格式为四位数字.但是,有些ID仅为3,例如"A05".有没有一种简单的方法可以自动添加一个"0"以使其类似于"A005"?

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"?

推荐答案

也许此报告者将为您工作-应该在第二个位置添加零,直到字符串长度为4或更大.

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

这篇关于NetLogo-自动在字符串中再添加一位数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆