Darwinbots Forum
Code center => Darwinbots Program Source Code => Topic started 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?
-
myerray = split("hi I am a humen", " ")
myerray(3) <> "human" etc etc etc...
-
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
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.
-
I hoped there would be a command for it, if it is to loop I can fix it on my own
-
Sorry, no shortcuts that I am aware of.
-
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