We help IT Professionals succeed at work.

asp classic find word in string and get its value

Wayne Barron
Wayne Barron asked
on
419 Views
Last Modified: 2017-03-28
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

CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Wayne BarronAuthor, Web Developer
CERTIFIED EXPERT
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
CERTIFIED EXPERT
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

CERTIFIED EXPERT

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
CERTIFIED EXPERT
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
CERTIFIED EXPERT

Commented:
Noted, and it seems there's a lot of excitements in your projects. All the best!
Wayne BarronAuthor, Web Developer
CERTIFIED EXPERT
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