Parsing Data in ASP

L

Lisa

I have a select statement that gives me the following results (for
example) "test documentation/software product version document.doc" I
need to parse the data to only grab everything between the "/" and
".". So, in other words, "software product version document" - I have
absolutley no idea how to do this - can anyone help????

Thanks in advance!
Lisa
 
B

Bob Barrows [MVP]

Lisa said:
I have a select statement that gives me the following results (for
example) "test documentation/software product version document.doc" I
need to parse the data to only grab everything between the "/" and
".". So, in other words, "software product version document" - I have
absolutley no idea how to do this - can anyone help????

Thanks in advance!
Lisa
I need to ask: is this truly represtative of your data? Could there be more
than one "/", or more than one "."? If so, you need to let us know if you
want the parsing to start at the first or last incidence of each character.

Do you need the Select statement to return the entire string? If not, then
let us know what database type and version you are using so we can show you
how to do it in your query.

If you need both the entire string, and you need to parse it as well, then
you will be better off doing it in vbscript in your asp page.
Bob Barrows
 
L

Lisa .

Bob,
Yes that is an actual representative of my data. The only "variable"
would be anything betweem "/" and ".". An actual example of my select
results is: "Testing Documentation/Borland JBuilder 6.0 Validation
Document.doc"

My code looks like this:
Dim strOldDocName, strIncremental, GetFileName, fullFileName
strOldDocName = softwareManufacturer + " " + softwareProduct + " " +
softwareVersion

set OBJcmd = Server.CreateObject("Adodb.command")
Set OBJcmd.ActiveConnection = oConn OBJcmd.CommandText = "SELECT * FROM
DocMd WHERE URL LIKE '%" & strOldDocName & "%' ORDER BY URLID DESC;"
Set rs = OBJcmd.execute

fullfilename = rs.Fields("URL")- this is was generates the data
mentioned above.

strIncremental = FullFileName + "1"

I need "strIncremental" to actually equal Parsed(FullFileName) + 1

If NOT rs.EOF THEN
GetFileName = strIncremental
Else
GetFileName = strOldDocName
End If

Lisa
 
B

Bob Barrows [MVP]

Lisa said:
Bob,
Yes that is an actual representative of my data. The only "variable"
would be anything betweem "/" and ".". An actual example of my select
results is: "Testing Documentation/Borland JBuilder 6.0 Validation
Document.doc"

You see? There are two "."'s there. Will it always be the last "." that you
want?
My code looks like this:
Dim strOldDocName, strIncremental, GetFileName, fullFileName
strOldDocName = softwareManufacturer + " " + softwareProduct + " " +
softwareVersion

set OBJcmd = Server.CreateObject("Adodb.command")
Set OBJcmd.ActiveConnection = oConn OBJcmd.CommandText = "SELECT *

Don't be lazy. Avoid select * in production code:
http://www.aspfaq.com/show.asp?id=2096
FROM DocMd WHERE URL LIKE '%" & strOldDocName & "%' ORDER BY URLID
DESC;" Set rs = OBJcmd.execute

fullfilename = rs.Fields("URL")- this is was generates the data
mentioned above.

Will you be doing anything else with fullfilename besides parsing it? Based
on this code, the answer is no, but there may be code you haven't shown us

Bob Barrows
 
L

Lisa .

You see? There are two "."'s there. Will it always be the last "." that
you
want?
and that will be my only referrence to FullFileName.

Lisa
 
B

Bob Barrows [MVP]

Lisa said:
You see? There are two "."'s there. Will it always be the last "."
that you
want?

and that will be my only referrence to FullFileName.

Lisa
What database are you using? This can probably be done in your query.

Bob Barrows
 
B

Bob Barrows [MVP]

Lisa said:
sorry I thought I posted my database info in my last message... I'm
using SQL 7

~L~

OK, here's a SQL 7+ solution (you should probably encapsulate this in a
stored procedure rather than using dynamic sql):

Dim sSQL
sSQL = Select substring(REVERSE(Right(reverse(URL), " & _
"len(URL) - charindex('.',REVERSE(URL)))),charindex('/',URL) " & _
"+ 1,100) as filename FROM DocMd WHERE URL LIKE '%" & _
strOldDocName & "%' ORDER BY URLID DESC;"
'for debugging:
'response.write sSQL
Set rs=oConn.Execute(sSQL,,1)
parsedFilename = rs("filename")

Bob Barrows
 
L

Lisa .

Bob,
I found what I was looking for....thought I would share, thanks!

Dim strOldDocName, strIncremental, GetFileName, fullFileName
strOldDocName = softwareManufacturer + " " + softwareProduct + " " +
softwareVersion

set OBJcmd = Server.CreateObject("Adodb.command")
Set OBJcmd.ActiveConnection = oConn
OBJcmd.CommandText = "MY SELECT STATEMENT;"
Set rs = OBJcmd.execute

fullFileName = rs.Fields("URL")
Dim text, found, arrText, newDoc
text = fullfilename
arrText = Split(text,"/")
For each item in arrText
if InStr(item,".doc") > 0 then
newDoc=replace(item,".doc","")
end if
next
strIncremental = newDoc + "1"
If NOT rs.EOF THEN
GetFileName = strIncremental
Else
GetFileName = strOldDocName
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top