FrontPage

Praat Script Tips

equivalent to split function in Perl

string$ = "hoge/piyo/foo/bar"
delimiter$ = "/"

n = 0
arr_0$ = string$
repeat
    lastValue$ = arr_'n'$
    delimiterPos = index(lastValue$,delimiter$)
    if delimiterPos <> 0
        arr_'n'$ = left$(lastValue$,delimiterPos-1)
        n = n+1
        arr_'n'$ = right$(lastValue$,length(lastValue$)-delimiterPos-length(delimiter$)+1)
    endif
until delimiterPos = 0

clearinfo
for i from 0 to n
    tmp$ = arr_'i'$
    printline 'tmp$'
endfor

Path Separator

#pathSep$ = "/"
pathSep$ = "\"

form foo
  : (omitted)
endform

if pathSep$ = "\"
    notPathSep$ = "/"
elsif pathSep$ = "/"
    notPathSep$ = "\"
else
    exit "Unknown path separator!"
endif
input$ = replace$(input$,notPathSep$,pathSep$,0)
output$ = replace$(input$,notPathSep$,pathSep$,0)

Upper to Lower Case

new$ = replace_regex$ (test$, "[A-Z]", "\L&", 0)

or even

new$ = replace_regex$ (test$, ".", "\L&", 0)

(it doesn't do full international lowercasing)

Front page   New List of pages Search Recent changes   Help   RSS of recent changes