Search for information by content and not by array position

0

I want to search for a certain word in a different way, I just got the one described below:

<%
mystring = "Como eu faço para separar uma string em várias strings?"
myarray = Split(mystring, " ")
For i = 0 to Ubound(myarray)
  Response.Write i & " - " & myarray(i) & "<br>"
  if myarray(0) = "Como" then
    existe = "Sim"
  Else
    existe = "Nao"
  end if
Next
Response.Write "Resposta Final >" & existe
%>

0 - Como
1 - eu
2 - faço
3 - para
4 - separar
5 - uma
6 - string
7 - em
8 - várias
9 - strings?

Final Response> Yes

I want to look in all the string that I turned into array, looking not for position myarray(0) zero, for example, but for myarray(i) , however the result comes "No", I need use this structure in another project that uses CheckBox's and I will never know which position will come. You can change to myarray(i) form.

    
asked by anonymous 05.11.2014 / 19:54

3 answers

2

Your result comes "No" because in the next step the answer is no. Once you find the result, you need to exit the loop:

<%
mystring = "Como eu faço para separar uma string em várias strings?"
myarray = Split(mystring, " ")
For i = 0 to Ubound(myarray)
  Response.Write i & " - " & myarray(i) & "<br>"
  if myarray(i) = "Como" then
    existe = "Sim"
    Exit For
  Else
    existe = "Nao"
  end if
Next
Response.Write "Resposta Final >" & existe
%>

    
05.11.2014 / 20:13
0

You can use the split function. Here's the example:

<!DOCTYPE html>
<html>
<body>

<%

myString=Split("Como eu faço para separar uma string em várias strings?")
for each x in myString
   response.write(x & "<br>")
next

%>  

</body>
</html>

For further questions link

    
05.11.2014 / 20:07
0

Do you really need to transform into array? If you do not need to use regular expression, it is much more effective. Below is an example in php, just convert to asp.

$str = "Como eu faço para separar uma string em várias strings?";
$ret = preg_match("/eu/", $str);
//$ret retorna true no caso acima
    
05.11.2014 / 21:02