[[FrontPage]]

* Praat Script Tips [#s823a6ce]

#contents

** equivalent to '''split''' function in Perl [#r73a5d35]
- 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 'tmp$'
 endfor

** Path Separator [#wa2b03b8]
- useful especially in Cygwin

 #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 [#idd10905]
- source: http://uk.groups.yahoo.com/group/praat-users/message/5278

 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