String contains another string e.x.(This string blah ... contains ... This)
Author |
Message |
fletch_to_99
|
Posted: Mon Apr 23, 2012 12:52 pm Post subject: String contains another string e.x.(This string blah ... contains ... This) |
|
|
What is it you are trying to achieve?
Check if a string contains another string.
What is the problem you are having?
No method or function for it? Looking for a function that returns true if it contains the string otherwise false (such as in java "blahblahblah".contains("test") would return false but "lol".contains("lol") would return true)
Describe what you have tried to solve this problem
Searching for a function for this, non found. Currently using exact matches but thats not what I want.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Currently uses exact matches however that is not the best way for this to be achieved.
Turing: |
proc search (criteria : string, students : array 1 .. * of Assignment )
var found : boolean := false
for i : 1 .. upper (students )
if students (i ).Name = criteria then
found := true
put "-------------------------"
put "Name: ", students (i ).Name
put "Grade: ", students (i ).Grade
put "Mark: ", students (i ).Mark
put "-------------------------"
end if
end for
if found then
return
end if
put "No student found!"
end search
|
Please specify what version of Turing you are using
Latest Stable (4.1.1) |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Raknarg
|
Posted: Mon Apr 23, 2012 1:22 pm Post subject: RE:String contains another string e.x.(This string blah ... contains ... This) |
|
|
Theres a thing called index. For example:
index ("Hello", "e") results a 2
index ("My name is George", "name") results 4
index ("ABCDEF", "Z") results a 0
It tells you where a pattern is. If it's not there, it results a 0.
Also, if you are going to make your own, a function would make more sense. |
|
|
|
|
|
evildaddy911
|
Posted: Mon Apr 23, 2012 4:19 pm Post subject: Re: String contains another string e.x.(This string blah ... contains ... This) |
|
|
Quote: Turing: | if found then
return
end if |
in turing, you use "result", and it has to be in a function, not a procedure. as for writing your own function, essentially, justdo exactly what raknarg says index does: Quote: If it's not there, it results a 0. (or a boolean) |
|
|
|
|
|
Raknarg
|
Posted: Tue Apr 24, 2012 11:41 am Post subject: RE:String contains another string e.x.(This string blah ... contains ... This) |
|
|
Or, he could just use the built-in index function.
Also, he can use return when using a procedure, thanks for that, I didn't know. When you use return, it completely exits the procedure, no matter where it is. That's useful if you're trying to return multiple values. |
|
|
|
|
|
|
|