You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pine Script中获取字符串指定字符出错,如何解决?

Pine Script取字符串字符错误的原因与解决办法
  • 错误原因:你用的myString[1]是Pine Script的序列历史索引语法,作用是获取该变量在上一根K线的取值,而非字符串的字符索引。因为你定义的myString是固定字符串,每根K线的取值都是"Hello",所以[1]返回的还是完整字符串。
  • 正确方法:Pine Script中提取字符串指定位置的字符,需要使用str.get()函数,语法为str.get(目标字符串, 字符索引)(索引从0开始计数)。

正确代码示例:

string myString = "Hello"
string secondChar = str.get(myString, 1) // 得到"e"

内容的提问来源于stack exchange,提问作者Ocean Overflow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 21:27:02