FrontPage
Praat Script Tips †
equivalent to split function in Perl †
- the subscripts start at 0.
- the last subscript is set to n.
- delimiter$ is specified literally (i.e., not in regular expressions)
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 'i''tab$''tmp$'
endfor
Path Separator †
- useful especially in Cygwin
input$ = "c:/foo/bar/hoge.TextGrid"
output$ = "c:/foo/bar/result"
#pathSep$ = "/"
pathSep$ = "\"
if pathSep$ = "\"
notPathSep$ = "/"
elsif pathSep$ = "/"
notPathSep$ = "\"
else
exit "Unknown path separator!"
endif
input$ = replace$(input$,notPathSep$,pathSep$,0)
output$ = replace$(output$,notPathSep$,pathSep$,0)
clearinfo
printline 'input$'
printline 'output$'
Upper to Lower Case †
string$ = "ABCDEFG"
newstring$ = replace_regex$(string$,"[A-Z]","\L&",0)
clearinfo
printline 'newstring$'