Computer Science Canada checking strings |
Author: | bmass [ Tue Nov 14, 2006 10:09 pm ] |
Post subject: | checking strings |
Hey there, is there a way to check if a string contains a certain set of characters. Not if a string is equal to a certain set of characters but for example, if I have a variable string that is "Vanilla cookie with sprinkles, peanuts, almonds", I want to have an if statement where the condition is whether a variable has "peanuts" anywhere in the string. How can I do this? Thanks. |
Author: | TokenHerbz [ Tue Nov 14, 2006 11:23 pm ] | ||
Post subject: | |||
Here i made you a very small program which dose what you ask.
1) its case sensitive 2) its not flexible Ill let you optomize it... |
Author: | zylum [ Tue Nov 14, 2006 11:23 pm ] |
Post subject: | |
you can use the index method. for more info on strings, check out cervantes' tutorial |
Author: | bmass [ Wed Nov 15, 2006 8:56 am ] | ||
Post subject: | |||
Thanks TokenHerbz. Can this be used in arrays? For example:
Where name(1 - 12) and final(1 - 12) are defined earlier in the code? |
Author: | Clayton [ Wed Nov 15, 2006 9:31 am ] |
Post subject: | |
errr... you don't put functions in loops.... read up on the function tutorial in the Turing Walkthrough, right now though, if you are only looking for the string once or twice, you could get away just doing the index function in your main line. TokenHerbz... your not really supposed to just give away the answer to the person, you should know this by now. |
Author: | TokenHerbz [ Wed Nov 15, 2006 11:18 am ] |
Post subject: | |
its not an answer if he dosn't know how to use it... its a guild line, he'll have to play around with it and learn it, understand it to optomize it for the whole thing he needs it to do. |
Author: | wtd [ Wed Nov 15, 2006 5:41 pm ] | ||||
Post subject: | |||||
Doing way too much work here.
|
Author: | bmass [ Wed Nov 15, 2006 7:42 pm ] |
Post subject: | |
Well actually, I need it to check a number of variables defined by the user. I currently have: get number var project : array 1 .. number of string for x : 1 .. number project(x) := project(x) + other(x) end for And then I need for certain strings added by 'other' in project(x) |