Splitting a Line of Text on Spaces

June 3, 2005 on 5:53 pm | In Generic Clips, Notetab Clips | No Comments

You can create an array by dividing on a set character. In this example I split on spaces per the request of the writer.

;*** Effort by Don Passenger
;*** don a-t htmlfixit d-o-t com
;*** discuss things live in chat at http://htmlfixit.com
;*******************************************************
;I assume each line in the file is this 9 field data format:
;"title 1 some text title 2 other text 567034"

;start at the top (assuming whole file)
^!Jump Doc_Start

;set list delimiter to space and get array elements
^!SetListDelimiter " "

:Loop
;get the row we are in
^!Set %row%="^$GetRow$"
;select the current line where cursor resides
;this will select the entire line from prior
;line feed to this one
^!Select Paragraph
;delimited array set by splitting line on spaces
^!SetArray %delimited_data%=^$GetSelection$
^!Set %indx%=1
:Loop_Display
;display each array element
^!Info Row is: ^%row% ^PElement ^%indx% is ^%delimited_data^%indx%%
;check if we have used all elements in current row
;compare current index number to number of elements
;in the array using delimited_data0 - which stores
;the number of elements in an array
^!If ^%indx% = ^%delimited_data0% Next_Line

^!Inc %indx%
^!Goto Loop_Display
;move to next line and then continue
:Next_Line
;go to next line
^!Jump Select_End
;loop again if there are more rows
^!If ^%row% = ^$GetLinecount$ END ELSE Loop

Significant points in this clip:
1. use of the ^!SetArray command to divide on a preset delimiter (in this case a space)
2. use of the special 0 element in the array to determine how many elements are in the array
3. use of the line: “^!If ^%row% = ^$GetLinecount$ END ELSE Loop” to test if we are at the end of our file
testing if you are at the end of a file is a common necessity in notetab clips.

No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds. Valid XHTML and CSS. ^Top^

Bad Behavior has blocked 497 access attempts in the last 7 days.