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

Username:   Password: 
 RegisterRegister   
 Grouping by Name Not Grouping Correctly
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
hamid14




PostPosted: Wed Jan 20, 2010 7:48 pm   Post subject: Grouping by Name Not Grouping Correctly

I have turing version 4.1. My problem is that my grouping code is not working. I am still not sure how the index command works. If someone can explain it to me better it would be great.

i did something like this, every name ends up in group 1

var name : string

get name
if index ("a".name) not=0 then
put "You are in group 1
end if

Thanks in advance.
Sponsor
Sponsor
Sponsor
sponsor
TheGuardian001




PostPosted: Wed Jan 20, 2010 8:17 pm   Post subject: Re: Grouping by Name Not Grouping Correctly

That program (well, that program with the typos fixed) does not put everyone into group 1... In fact, it won't put anybody in group 1 unless they enter "a" as their name.

the index (sourceString, searchString) command works by looking for the first occurrence of searchString in sourceString, and then returning the index of the first character that string occurred at (or 0 if it wasn't found at all).

For example, index("this is a string","a") would return 9, since "a" is first found in "this is a string" at character 9. index("string goes here", "a") would return 0, since "a" is not found in "string goes here".

In case you don't have it, the documentation can be found here: index
andrew.




PostPosted: Wed Jan 20, 2010 8:29 pm   Post subject: RE:Grouping by Name Not Grouping Correctly

You have to use something like:
Turing:
get name : *
if index (name, "a") not = 0 then
    put "You are in group 1"
end if
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: