Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Other Development Tools
 ASP: find the occurence and position of a variable

Author  Topic 

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2005-10-10 : 15:57:30
hello,
how do i find the occurence and position of a variable in a csv string.

e.g.

how do i find "hello" in
hi,who,where,how,hello,greetings,xmas,etc

The starting position and if it occurs ?
I tried using instr but cant seem to get it right

any advice ?
thanks
Afrika

MichaelP
Jedi Yak

2489 Posts

Posted - 2005-10-10 : 16:12:59
Well, instr worked for me. Remember, instr just returns you the starting posistion of the given string.

If you paste this into a .asp page, you should see how it all works.

<%
Dim sCSV

sCSV = "hi,who,where,how,hello,greetings,xmas,etc"

response.write "The location is:" & instr(sCSV, "hello") & "<BR>"


Dim i
Dim aryCSV

aryCSV = split(sCSV, ",")

for i = 0 to ubound(aryCSV) -1
response.write "I:" & I & " Value:" & aryCSV(i) & "<BR>"
next

%>

Michael

<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2005-10-11 : 05:04:31
Ok thanks Michael
my error was i omitted the array variable (i)

thanks
afrika
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2005-10-11 : 05:06:47
i was also using
quote:

Dim i
Dim aryCSV

aryCSV = split(sCSV, ",")
Counter = ubound(aryCSV)

for i = 0 to ubound(aryCSV) -1
help = instr (aryCSV,counter)
next
Go to Top of Page
   

- Advertisement -