
-----------------------------------
ThgilFoDrol
Fri Nov 02, 2012 10:45 am

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.

-----------------------------------
Aange10
Fri Nov 02, 2012 11:54 am

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") 
[/code]

-----------------------------------
Tony
Fri Nov 02, 2012 12:19 pm

RE:Check if a string contains a word/sentence etc in Turing
-----------------------------------
[tdoc]index[/tdoc]

-----------------------------------
Aange10
Fri Nov 02, 2012 12:44 pm

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
Fri Nov 02, 2012 3:54 pm

Re: RE:Check if a string contains a word/sentence etc in Turing
-----------------------------------
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
Fri Nov 02, 2012 9:58 pm

Re: RE:Check if a string contains a word/sentence etc in Turing
-----------------------------------
Not to OT, but:

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.

->


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.
