Think of something that you wish Authorware could do but it doesn't? Let the our good friends at Macromedia know via the wishlist. Please let us know if you find any of the materials on this site inappropriate or offensive. Please include the url and why the material should be reviewed. Comments and questions about the site are also welcome. Please no Authorware questions, use the AWARE list. |
Back
B8001 - How do I find out on which line number a string of text is found? by - Joseph Ganci Thanks to Kevin Warner for this clever solution:
Remember that functions are executed from the inside out. Therefore, the
first thing that will happen in the above line is that the Find function
will search for the target string (contained in the user variable TargetString)
within the text (contained in the user variable EntireText). The result
of this will be the exact position number in the string at which the target
string is found. This number is then passed as the third argument to the SubStr
function, which will make a copy of the text from the first character to the
character whose position has just been defined by the Find function.
The copied text is then passed to the LineCount function which returns
the number of lines in the copied text. Since the target position is on the
last line of the copied text, this is equivalent to the line number in the original
text in which the text was found. EntireText := "Authorware is by far the best authoring system\rnot only
in the world, but in the universe. No\rauthoring system can compare to the
features found\rin this most excellent application\r." In the above text, if we were to search for the word "features" using Kevin
Warner's method: LineNo:=LineCount(SubStr(EntireText,1,Find(TargetString,EntireText))) the Find function will return 131, because it is found in the 131st
position of the string (notice the Return characters count as well). The substring
that is returned by the SubStr function returns the following: Authorware is by far the best authoring system not only in the world,
but in the universe. No authoring system can compare to the features
found in this most excellent applicaiton. The LineCount function then returns 3 which indicates that there are three
lines in the resulting string, which is the same as saying that the target was
found on the third line of the original string. LineNum := 0 This too will find only one target in the string. It will loop through
the contents of the EntireText variable one line at a time using the
GetLine function. Once it finds the target, it sets the LineNum
variable to the first line on which the target is found, then it exits the
loop. LineNum := "" This creates a text list in the variable LineNum, each line number
divided by a comma. Add your review Back |