asp classic find word in string and get its value

Wayne Barron
Wayne Barron used Ask the Experts™
on
Hello All;

theString = "A lot of information is here, and we just want to get this one string and post back it''s data to the page. We are hunting for [imge:filename.jpg] and then we are going to work with it on the page."

OK, in the "theString" above, we need to first find
[imge:filename.jpg]
And then we need to get the value.
filename.jpg

I need to return the value (not a number, but the actual value) of the name.
filename.jpg

Any idea's on this one?
Carrzkiss
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Team Lead
Commented:
a quick and dirty solution:

<%

theString = "A lot of information is here, and we just want to get this one string and post back it''s data to the page. We are hunting for [imge:filename.jpg] and then we are going to work with it on the page."

fileName = Split(Split(Split(theString, "[") (1), "]") (0), ":") (1)

response.write "theString = " & theString & "<br>fileName = " & fileName

%>

Open in new window

Wayne BarronAuthor, Web Developer
Top Expert 2009

Author

Commented:
Nice, thanks, Ryan.

I changed it up a little, to make sure that it only grabs that tag.

fileName = Split(Split(Split(theString, "[image") (1), "]") (0), ":") (1)


Works great.
Much appreciated.

Wayne
Wayne BarronAuthor, Web Developer
Top Expert 2009

Author

Commented:
Hey, Ryan.

How would you bypass this function IF there i no image tag in the string?

Example

Code with image tag. (This works great)
<%
theString = "A lot of information is here, and we just want to get this one string and post back it''s data to the page. We are hunting for [image:filename.jpg] and then we are going to work with it on the page."
fileName = Split(Split(Split(theString, "[image") (1), "]") (0), ":") (1)
response.write "theString = " & theString & "<br>fileName = " & fileName
%>

Open in new window


Code WITHOUT image tag. (Subscript out of range: '[number: 1]')
<%
theString = "This string does not have an image tag in it, so it is not going to result in nothing from the SPLIT."
fileName = Split(Split(Split(theString, "[image") (1), "]") (0), ":") (1)
response.write "theString = " & theString & "<br>fileName = " & fileName
%>

Open in new window

Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Ryan ChongSoftware Team Lead

Commented:
How would you bypass this function IF there i no image tag in the string?
we will need to have a pattern for parse the string. so we gonna built that logic for text extraction.
Wayne BarronAuthor, Web Developer
Top Expert 2009

Author

Commented:
Hey, Ryan.
I took a different path.
Instead of Generating the code
[image:imagename.jpg]

Open in new window

I am generating the Image and users name.
[image:username|imagename.jpg]

Open in new window

And then processing it out in the code.
So, this works.

I was looking at the way I was trying. (The reason for the thread)
And I saw that it would be resource intensive, and it would only do one tag.
What if there were multiple tags.

So, I decided that the best thing to do would be better something that is best on the system, and better on coding as well.
Would be to just add the user's name to the image tag, and process it with the page, instead.

Thanks for your assistance once again.
I will be able to use your code, provided here for a future project.

Take care, Ryan.
Wayne
Ryan ChongSoftware Team Lead

Commented:
Noted, and it seems there's a lot of excitements in your projects. All the best!
Wayne BarronAuthor, Web Developer
Top Expert 2009

Author

Commented:
Hey, Ryan.
Oh, Yeah!
There is a lot of excitement about this project, as it is a MAJOR update to the site.
However, the other projects. Now, that one has me jumping for joy and doing flips.
Something I have been wanting to do since I first started doing this thing we call, database driven web design.

Have a good one, Ryan.
Wayne

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial