Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Turing word highlighter only highlights the first occurrence of the word
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Danyn




PostPosted: Sun Dec 15, 2013 12:34 am   Post subject: Turing word highlighter only highlights the first occurrence of the word

What is it you are trying to achieve?
Highlight all the occurrences of the word.

What is the problem you are having?
It only highlights the first occurrence of the word.

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:


var sent, word : string
var firstPart, secondPart : int
word := "is"

sent := "This is a test to highlight a word!"

put sent


loop
    color (black)
    firstPart := index (sent, word)
    put sent (1 .. firstPart - 1) ..
    secondPart := index (sent, word) + length (word)
    color (red)
    put sent (firstPart .. secondPart - 1) ..
    color (black)
    put sent (secondPart .. *)
end loop




Please specify what version of Turing you are using
4.11
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Sun Dec 15, 2013 2:44 am   Post subject: RE:Turing word highlighter only highlights the first occurrence of the word

Because that's what you told it to do. Index only finds the first occurrence of a pattern for you. Somehow you have to find a way to make it ignore or forget the portion of the word it's already looked at.
evildaddy911




PostPosted: Sun Dec 15, 2013 11:06 am   Post subject: RE:Turing word highlighter only highlights the first occurrence of the word

heres a hint: try to figure out the code for index(). then use that code to make your own slightly modified version. the one i use returns an integer array instead of a single int, but you dont have to make it a function at all, just replace the result statements with other code
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: