473,387 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Parsing text for conversion

Hi

In my main 'submit news' admin for a site I am doing, I want to be able to
offer the person submitting the news the ability to reference other files
within their text without the need to use HTML.
My proposal is to use [square brackets] within the text that will then be
parsed when the page is rendered from the database. At present I have this -
e.g.

To download the file [file.exe, click here].

Which I want to render with the words 'click here' as being a link to
file.exe.

I'm very familiar with instr, replace and split (all of which I think I
would need to use) but I cannot figure out how to parse the above text in
the way I want.

Can anyone offer me some guidance, please? Thanks.
Jul 19 '05 #1
2 1342
"David McManus" wrote ...
Can anyone offer me some guidance, please? Thanks.


Split it up a bit...

[file]file.exe[/file]

<%
strContent = Request.Form("content")

strContent = Replace(strContent, [file], "<a href=""")

strContent = Replace(strContent [/file], """ title=""Click here"">Click
here</a>")
%>

If I've got right number of " 's in there - you should be able to enter
something like :

[file]http://mydomain.com/files/myfile.zip[/file]

and it should then produce :

<a href="http://mydomain.com/files/myfile.zip" title="Click here">Click
here</a>

for you...

bare in mind that if you are going to offer an 'edit' facility for the news
items, you'll need to be able to convert the above back again into your
square brackets :o)

This then becomes fun when you start trying to distinguish files from urls
and mailto's ...

You could either have different square brackets for the different
iterations, or you could use ID values in the a href tags, therefore making
it easier to convert them back afterwards.

Hope this is of help.

Regards

Rob
Jul 19 '05 #2
Here is a script that I use when writing the information
from a database. It determines web and email links
automatically (but it does not allow you to specify text
to use for the link but I am sure you could add that
functionality). The other neat thing is that if the link
is inside of your site, it will open it up in the current
browser. If it is outside of your site then it will open
the link in a new window.

Watch for wrapping in the code.

Function InsertHyperlinks(inText)
Dim objRegExp, strBuf
Dim objMatches, objMatch
Dim Value, ReplaceValue, iStart, iEnd

strBuf = ""
iStart = 1
iEnd = 1
Set objRegExp = New RegExp

objRegExp.Pattern = "\b(www|http|\S+@)\S+\b" ' Match
URLs and emails
objRegExp.IgnoreCase = True ' Set case
insensitivity.
objRegExp.Global = True ' Set
global applicability.
Set objMatches = objRegExp.Execute(inText)
For Each objMatch in objMatches
iEnd = objMatch.FirstIndex
strBuf = strBuf & Mid(inText, iStart, iEnd-iStart+1)
If InStr(1, objMatch.Value, "@") Then
strBuf = strBuf & GetHref
(objMatch.Value, "EMAIL", "_self")
Else
IF inStr(objMatch.Value,"yoursite.com") THEN
strBuf = strBuf & GetHref
(objMatch.Value, "WEB", "_self")
ELSE
strBuf = strBuf & GetHref
(objMatch.Value, "WEB", "_blank")
END IF
End If
iStart = iEnd+objMatch.Length+1
Next
strBuf = strBuf & Mid(inText, iStart)
InsertHyperlinks = strBuf
End Function
Function GetHref(url, urlType, Target)
Dim strBuf

strBuf = "<a href="
If UCase(urlType) = "WEB" Then
If LCase(Left(url, 3)) = "www" Then
strBuf = "<a href=""http://" & url & """ Target="""
& Target & """>" & url & "</a>"
Else
strBuf = "<a href=""" & url & """ Target=""" &
Target & """>" & url & "</a>"
End If
ElseIf UCase(urlType) = "EMAIL" Then
strBuf = "<a href=""mailto:" & url & """ Target=""" &
Target & """>" & url & "</a>"
End If

GetHref = strBuf

End Function
-----Original Message-----
Hi

In my main 'submit news' admin for a site I am doing, I want to be able tooffer the person submitting the news the ability to reference other fileswithin their text without the need to use HTML.
My proposal is to use [square brackets] within the text that will then beparsed when the page is rendered from the database. At present I have this -e.g.

To download the file [file.exe, click here].

Which I want to render with the words 'click here' as being a link tofile.exe.

I'm very familiar with instr, replace and split (all of which I think Iwould need to use) but I cannot figure out how to parse the above text inthe way I want.

Can anyone offer me some guidance, please? Thanks.
.

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
9
by: Mantorok Redgormor | last post by:
If I am parsing a config file that uses '#' for comments and the config file itself is 1640 bytes, and the format is VARIABLE=VALUE, is it recommended to use a) fgetc (parse a character at a...
7
by: Alan | last post by:
Hi. I have programmed in C++ before, but I`m a couple of years out of practice. I am seeking some advice on getting started on a quickie project. . . . I have to read a 54MB text file and do a...
3
by: Aaron | last post by:
I'm trying to parse a table on a webpage to pull down some data I need. The page is based off of information entered into a form. when you submit the data from the form it displays a...
0
by: Michiel Sikma | last post by:
Hello everybody. I'm kind of new to Python. I'm working on a simple text parser that will allow me to transform a certain syntax into a certain output. I find wikis interesting, so wiki to HTML...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
6
by: i_robot73 | last post by:
I have a file, containing hex values for dates (MMDDYYYY)<status code><??such as: ...
2
by: =?ISO-8859-1?Q?Andr=E9?= | last post by:
Hi everyone, I would like to implement a parser for a mini-language and would appreciate some pointers. The type of text I would like to parse is an extension of: ...
6
by: gw7rib | last post by:
I have a program that needs to do a small amount of relatively simple parsing. The routines I've written work fine, but the code using them is a bit long-winded. I therefore had the idea of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.