Solved

split string array with / in it.

Posted on 2013-02-03
5
314 Views
Last Modified: 2013-02-05
Hello All;

OK, I have a string like so.

Photoshop / After Effects
(or)
Access / Excel / Word
(or)
SQL Server

So it could have a / in the string, or there could not be, or there could be many of them.
It all really depends.
I need to replace the "Name" with an image
Like what you would do here.

if str = "Photoshop" then
WriteStr = "PS.jpg"
end if

I found this code, however, I cannot get it to show the images for each one, if there is more than one in the string.

This is within a LOOP, as shown in the code below.

<%
while not rs.eof
' There could be:
' Photoshop / After Effects
' (or)
' Access / Excel / Word
' (or)
' SQL Server
' In the following record, we need to SPLIT them form the / and then replace each item with an image.
' So if there is 3 items, then we need to have 3 images.
' and if there is 1 item, then we need only 1 image (This works)

myString = rs("MyField")

MyArray = split(VidCat,"/")
for counter = 0 to ubound(MyArray)
if MyArray(counter) = "Photoshop" then
response.Write  "<img src=""graph/Programs/PS.jp<wbr ></wbr>g"" height=""25"" />"
end if
if MyArray(counter) = "After Effects" then
response.Write  "<img src=""graph/Programs/AE.jp<wbr ></wbr>g"" height=""25"" />"
end if
if MyArray(counter) = "Sony Vegas" then
response.Write  "<img src=""graph/Programs/SonyV<wbr ></wbr>egas.jpg""<wbr ></wbr> height=""25"" />"
end if
if MyArray(counter) = "Adobe Edge Animate" then
response.Write  "<img src=""graph/Programs/An.jp<wbr ></wbr>g"" height=""25"" />"
end if
next
rs.movenext
wend
' This all works, except when there is multiple entries / within the string.
%>

Open in new window


Thanks All
Carrzkiss
0
Comment
Question by:Wayne Barron
  • 3
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
madgino earned 500 total points
ID: 38850060
On line 15 you are spliting VidCat instead of mystring; then you have to use trim to eliminate spaces:

<%
while not rs.eof
' There could be:
' Photoshop / After Effects
' (or)
' Access / Excel / Word
' (or)
' SQL Server
' In the following record, we need to SPLIT them form the / and then replace each item with an image.
' So if there is 3 items, then we need to have 3 images.
' and if there is 1 item, then we need only 1 image (This works)

myString = rs("MyField")

MyArray = split(myString,"/")
for counter = 0 to ubound(MyArray)
if trim(MyArray(counter)) = "Photoshop" then
response.Write  "<img src=""graph/Programs/PS.jp<wbr ></wbr>g"" height=""25"" />"
end if
if trim(MyArray(counter)) = "After Effects" then
response.Write  "<img src=""graph/Programs/AE.jp<wbr ></wbr>g"" height=""25"" />"
end if
if trim(MyArray(counter)) = "Sony Vegas" then
response.Write  "<img src=""graph/Programs/SonyV<wbr ></wbr>egas.jpg""<wbr ></wbr> height=""25"" />"
end if
if trim(MyArray(counter)) = "Adobe Edge Animate" then
response.Write  "<img src=""graph/Programs/An.jp<wbr ></wbr>g"" height=""25"" />"
end if
next
rs.movenext
wend
' This all works, except when there is multiple entries / within the string.
%>

Open in new window

0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 38850069
It works.....
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 38851695
I've requested that this question be closed as follows:

Accepted answer: 0 points for carrzkiss's comment #a38850069

for the following reason:

Thanks, spoke to soon on the last comment, then edited it real quick.<br /><br />Thanks a bunch, did not think about the TRIM, everything else was correct.<br />And the VidCat, that was taken from the original code.<br />I just added in the TRIM() and everything went to working.<br />You rock.<br />Have a great week.<br /><br />Carrzkiss
0
 
LVL 30

Author Closing Comment

by:Wayne Barron
ID: 38851696
(Lets try this again, I accepted it last night, but it did not take, EE must be having issues again)

Thanks, spoke to soon on the last comment, then edited it real quick.

Thanks a bunch, did not think about the TRIM, everything else was correct.
And the VidCat, that was taken from the original code.
I just added in the TRIM() and everything went to working.
You rock.
Have a great week.

Carrzkiss
0
 
LVL 11

Expert Comment

by:madgino
ID: 38854010
Thanks
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now