如何循环遍历字符串并查看是否有”1″作为字符串的元素?

huangapple go评论75阅读模式
英文:

how to loop through a string and see if "1" is an element in the str?

问题

如果orderIds中存在一个名为"1"的元素,
则将buy1设置为true

orderIds = ""

for idx = 0 to strategy.opentrades - 1
    strSuffix = idx == strategy.opentrades - 1 ? "" : ", "
    orderIds += strategy.opentrades.entry_id(idx) + strSuffix
英文:

if orderIds has a present element called "1"
then buy1 = true

orderIds = ""

for idx = 0 to strategy.opentrades - 1
	strSuffix = idx == strategy.opentrades - 1 ? "" : ", "
	orderIds += strategy.opentrades.entry_id(idx) + strSuffix

答案1

得分: 0

orderIds = ""

for idx = 0 to strategy.opentrades - 1
	strSuffix = idx == strategy.opentrades - 1 ? "" : ", "
	orderIds += strategy.opentrades.entry_id(idx) + strSuffix

// 在图表上显示结果
label.new(bar_index, high, orderIds)

// 如果你的订单ID是"1",那么cakes = 12222
cakes = 10000

if str.contains(orderIds, '1')
    cakes := 12222

plot(cakes)
英文:
orderIds = ""

for idx = 0 to strategy.opentrades - 1
	strSuffix = idx == strategy.opentrades - 1 ? "" : ", "
	orderIds += strategy.opentrades.entry_id(idx) + strSuffix

//Show result on the chart
label.new(bar_index, high, orderIds)


// if your order ID is "1" then cakes = 12222 
cakes = 10000

if str.contains(orderIds, '1')
    cakes := 12222

plot(cakes)

huangapple
  • 本文由 发表于 2023年1月8日 23:06:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75048842.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定