Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search in a string

Status
Not open for further replies.

discusmania

IS-IT--Management
Oct 24, 2000
158
0
0
AP
Hi Guys....
Long time never see you all....
actually i have a question ...let say I have a string

stringA="199,99,203,20"

i want to search whether 99 exist in the string or not. I try to use instr(1,stringA,"99") but it return me both 99 and 199 which i dont want. i just want 99 alone. Anybody now how to do it?.

thanks,
Cheer up
 
hi,
u can split the above string using split function and u can check the values..
 
use the split function and search the resulting array as kaveri00 suggests, or, you can do something ugly (yet functional!) like this:

instr(1, "," & stringA & ",", ",99,") so that you are requiring commas on both sides of your value, acting like delimeters.

good luck!
 
Know that i can use split function but it will still be the same . When for 99 it will still give me 99 and 199

and about the comma i cannot do that cause the substring can be ,99 or ,99, or 99, depend on the location in the string.

Thanks anyway... any other idea?
 
You can use the Split() function as Funka and Kaveri00 suggested. When you do the compare, force the array values to an Int first using CInt().

Code:
stringA="199,99,203,20"

tempArray = Split(stringA,",")

For Each item in tempArray
  If CInt(item) = 99 Then
    '99 was found in the array so do your stuff here
    Exit For 'can exit the loop once you've found it
  End If
Next

Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
Thanks for your suggestion..
atually what I want ot do is , lets say i have a string
A="199,20,200,99,9" then when i open a window that list down checkbox for example :

1. ||199
2. ||34
3. ||70
4. ||200
5. ||50

I want checkboxes no 1 and no 4 will be checked cause the value is there in the string.

How to do that?
try to split it but does'nt work. Please help me.

Thanks and Regards
Ron
 
I think funka, festersxs and some others gave you the correct answer allready.

instr(1, "," & stringA & ",", ",99,")

or
if instr(1, "," & stringA & ",", ",99,") > 0 then

 
Is this what you want?

<%
Dim StrNum, StrSplitNum

strNum = &quot;31,45,99,199,464,6599,32,47,99,324&quot;
strSplitNum = Split(strNum,&quot;,&quot;)

For each sNumber in strSplitNum %>
<%=sNumber%> -- <input type=&quot;checkbox&quot; name=&quot;numbers&quot; value=&quot;<%=sNumber%>&quot;<% If Instr(sNumber, &quot;99&quot;) > 0 then Response.Write &quot; checked&quot;%>><br>
<% Next %> www.vzio.com
ASP WEB DEVELOPMENT



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top