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

Username:   Password: 
 RegisterRegister   
 Check if a string contains a word/sentence etc in Turing
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ThgilFoDrol




PostPosted: Fri Nov 02, 2012 10:45 am   Post subject: Check if a string contains a word/sentence etc in Turing

How do I check if a "get x" has a specific word/sentence in Turing? Is it possible in Turing? In java it's myString.contains(string[, separator]); how how would I do this in Turing? Thanks in advance.
Sponsor
Sponsor
Sponsor
sponsor
Aange10




PostPosted: Fri Nov 02, 2012 11:54 am   Post subject: RE:Check if a string contains a word/sentence etc in Turing

You can do it, you just have to make the .contains procedure.

It would look something like

code:
fcn contains (word, lookingFor : string) : boolean
     for i : 1 .. length(word)
     if word (i) = lookingFor then
        result true
     end if
end for
result false
end contains

var s : string := "Hello World"
put contains (s, "o")
Tony




PostPosted: Fri Nov 02, 2012 12:19 pm   Post subject: RE:Check if a string contains a word/sentence etc in Turing

index
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Aange10




PostPosted: Fri Nov 02, 2012 12:44 pm   Post subject: RE:Check if a string contains a word/sentence etc in Turing

Oh yes, I forgot about index. But the Turing index function is terrible considering it stops at the first occurrence of what you are looking for, and doesn't provide a way to look for more occurrences.

That would be why I do not use index.
Tony




PostPosted: Fri Nov 02, 2012 3:54 pm   Post subject: Re: RE:Check if a string contains a word/sentence etc in Turing

Aange10 @ Fri Nov 02, 2012 12:44 pm wrote:
it stops at the first occurrence of what you are looking for, and doesn't provide a way to look for more occurrences.

Considering that #contains() returns a boolean value, I don't see how this is a problem.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Aange10




PostPosted: Fri Nov 02, 2012 9:58 pm   Post subject: Re: RE:Check if a string contains a word/sentence etc in Turing

Not to OT, but:

Tony @ 2/11/2012, 2:54 pm wrote:
Aange10 @ Fri Nov 02, 2012 12:44 pm wrote:
it stops at the first occurrence of what you are looking for, and doesn't provide a way to look for more occurrences.

Considering that #contains() returns a boolean value, I don't see how this is a problem.


->

Aange10 wrote:

That would be why I do not use index.


Not saying it matters in this scenario (or in comparison to #contains() in java)

On the flip side, to the OP, Tony is correct about index being a valid and most likely superior way to solve your problem.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: