[[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 'i''tab$''tmp$'
 endfor

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

 string$ = "ABCDEFG"
 
 newstring$ = replace_regex$(string$,"[A-Z]","\L&",0)
 
 clearinfo
 printline 'newstring$'

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