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

如何在PRAAT中创建字符串数组并实现元素检索?

在Praat中实现字符串数组创建与元素检索

Praat没有原生的字符串数组类型,但可以通过两种方式模拟实现你要的功能:

方法一:使用Strings对象(推荐)

Praat的Strings对象专门用来存储字符串集合,操作更直观:

1. 创建字符串集合(对应Python的options=["a","b","cd"])

# 直接创建包含3个元素的Strings对象
Create strings: "options", 3
Set string: "options", 1, "a"
Set string: "options", 2, "b"
Set string: "options", 3, "cd"

或者用简洁方式一次性生成:

Create strings as file list: "options", "a" + newline$ + "b" + newline$ + "cd"

2. 遍历检索元素(对应你的目标逻辑)

模拟Input集合并遍历检查:

# 创建Input集合
Create strings: "Input", 3
Set string: "Input", 1, "ab"
Set string: "Input", 2, "cd"
Set string: "Input", 3, "ef"

# 遍历每个元素并检查是否在options中
for i from 1 to number_of_strings("Input")
    current$ = Get string: "Input", i
    # index_of_string返回元素位置,找不到则返回0
    if index_of_string("options", current$) > 0
        # 这里替换成你要执行的操作
        writeInfoLine: "匹配到元素: ", current$
    endif
endfor

方法二:用分隔符拼接字符串模拟数组

如果不想创建对象,可使用换行符作为分隔符,将字符串拼接成长字符串模拟数组:

# 模拟options数组
options$ = "a" + newline$ + "b" + newline$ + "cd"
# 模拟Input数组
Input$ = "ab" + newline$ + "cd" + newline$ + "ef"

# 遍历Input的每个元素
current$ = extractLine$ (Input$, 1)
i = 1
while current$ != ""
    # index_of_line检查元素是否存在,找不到返回0
    if index_of_line(options$, current$) > 0
        # 执行你的操作
        writeInfoLine: "匹配到元素: ", current$
    endif
    i = i + 1
    current$ = extractLine$ (Input$, i)
endwhile

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 14:03:20