Darwinbots Forum

Code center => Darwinbots Program Source Code => Topic started by: Zelos on November 02, 2005, 10:09:33 AM

Title: search
Post by: Zelos on November 02, 2005, 10:09:33 AM
If I have splited a sentence into arrays is it possible to search trough the arrays for a specefic word/sentence in the arrays, like I split "hi im a human" into "hi"/"im"/"a"/"human" and search for "human" and it tells me its in array 3?
Title: search
Post by: Botsareus on November 02, 2005, 10:48:49 AM
myerray = split("hi I am a humen", " ")

myerray(3) <> "human" etc etc etc...
Title: search
Post by: PurpleYouko on November 02, 2005, 11:38:07 AM
Why split it into arrays first?

It's just as easy to search through a string for a section of it.

All you need to do is use the mid function to compare strings.

Example
Code: [Select]
Sentence = "Hi. I am a Human!"
Searchstring= "Human"
SentenceLength = len(Sentence)
SearchLength = len(SearchString)
for t = 1 to SentenceLength - SearchLength
  test = mid(Sentence, t, SearchLength)
  If test = SearchString then
    condition = true
    exit for
  endif
next  t
This loop or something like it will search any length of string for any substring. You could build this into a function which you can call from any point in your program. Unless you have a good reason to convert your sentence into arrays, don't bother.
Title: search
Post by: Zelos on November 02, 2005, 01:35:38 PM
I hoped there would be a command for it, if it is to loop I can fix it on my own
Title: search
Post by: PurpleYouko on November 02, 2005, 01:59:35 PM
Sorry, no shortcuts that I am aware of.
Title: search
Post by: Zelos on November 02, 2005, 02:11:50 PM
its ok, ive already solved it, thx anyway
why I want to split it is cause im gonna use it in cell, the dna tells how the cell looks and I want to be able to show it before it and then I need to isolate the gene that contain birth appherens