I'm working on a simple click-through image gallery and I have images with
captions in two arrays like this:
var current_value=" 0";
var images = new Array
("photo01.jp g",
"photo02.jp g",
"photo02.jp g");
var captions = new Array
("caption1",
"caption2",
"caption3") ;
The large image views are shown in a window which I can link to with a
search substring URL defining which image to display: popup.html?imag e02.jpg
I then extract the search string like this:
display = window.location .search;
photo = display.substri ng (display.lastIn dexOf('?') +1);
By knowing the search substring value (in this case photo02.jpg) I would
like a regex function to search through the images array and find the match
(in this case index 1) and therafter use that index value to set the
current_value variable.
Does anyone have an idea how the searching and matching is done? 3 3083
Timmy wrote: I'm working on a simple click-through image gallery and I have images with captions in two arrays like this:
var current_value=" 0";
var images = new Array ("photo01.jp g", "photo02.jp g", "photo02.jp g");
var captions = new Array ("caption1", "caption2", "caption3") ;
The large image views are shown in a window which I can link to with a search substring URL defining which image to display: popup.html?imag e02.jpg
Do you mean: ...popup.html?p hoto02.jpg I then extract the search string like this:
display = window.location .search; photo = display.substri ng (display.lastIn dexOf('?') +1);
Your posted line will give:
photo = image02.jpg By knowing the search substring value (in this case photo02.jpg) I would like a regex function to search through the images array and find the match (in this case index 1) and therafter use that index value to set the current_value variable.
Does anyone have an idea how the searching and matching is done?
There are a couple of options, one is to loop through the array looking
for a matching image name:
var current_value = 0;
for (var i=0, n=images.length ; i<n && 0 == current_value; ++i){
if (images[i] == photo) current_value = i;
}
If you are only using 'current_value' to get the caption, why not store
the image name and caption in an object:
var photoCaption = {
"photo01.jp g" : "caption 1 text",
"photo02.jp g" : "caption 2 text",
"photo03.jp g" : "caption 3 text"
};
...
Having extracted the photo name from the search string:
var caption = photoCaption[photo];
--
Rob
RobG wrote:
[...] var current_value = 0; for (var i=0, n=images.length ; i<n && 0 == current_value; ++i){
Actually that isn't great because if you get a match at i=0 it will
still loop through all the images. Here's a slightly better version:
var i=0;
while ( images[i] != photo && images[++i] ) {
current_value = i;
}
if ( !images[i] ) {
// didn't find a match, deal with it
}
[...]
--
Rob
> Do you mean: ...popup.html?p hoto02.jpg
Yes thanks for figuring that and for the various solutions. I'll test. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tap |
last post by:
I would like to parse the following string with as little code as possible.
stringValue = "Email Message ID:TAPASVI to tapsbin@hotmail.com;tapasbin@cs.com;{CC}tapstemp@hotmail.com;{CC}tapstemp007@hotmail.com"
1) Take everything in between "ID:" and the word " to"
i.e. stringVal1 = "TAPASVI"
2) Take between the word " to " and "{CC}"
i.e. stringVal2 = "tapsbin@hotmail.com;tapasbin@cs.com;"
|
by: Steve |
last post by:
Hi,
I have an array of strings e.g. "one","two","three","four","fourteen"
From the following string "onethreefourteenten"
I would like to know that strings have been matched; strings
,, but not .
What i'm trying to get is the longest word beginning at a particular
|
by: Friday |
last post by:
Being an Old L.A.M.P guy, I beg you to please excuse my ignorance of
dot.net (and all things Windows, for that matter).
As part of an experiment (to learn enough ASP/VB.net to port a series
of existing PHP scripts of mine to work on IIS), I have created the
following simple function to compare a Website visitor's IP address
against a varabe-array. The experiment invovleas a common scenario --
banning a Website visitor by IP Address:
...
|
by: clintonG |
last post by:
I'm using an .aspx tool I found at but as nice as the interface is I
think I need to consider using others. Some can generate C# I understand.
Your preferences please...
<%= Clinton Gallagher
http://forta.com/books/0672325667/
|
by: JackRazz |
last post by:
Anyone know the regular expression to match a blank line where the byte sequence is
"0D 0A 0D 0A"
ive tried "\r\n\r\n+", "^$+" "\n\r" with no success. Any Ideas?
Thanks - JackRazz
This is the code fragment I'm trying
Dim r As Regex, m As Match, i As Integer
| |
by: Just Me |
last post by:
I want to use regular expressions to search a string, give the user the
option of replacing, and then maybe replacing the data - using reg
expressions for the search and the replace strings.
However all the Regex replace methods seem to combine in one call the search
and replace.
Is there a way of doing what I want?
|
by: lgbjr |
last post by:
Hi All,
I'm trying to split a string on every character. The string happens to be a
representation of a hex number. So, my regex expression is ().
Seems simple, but for some reason, I'm not getting the results I expect.
Dim SA as string()
Dim S as string
S="FBE"
|
by: Kofi |
last post by:
Any takers?
Got a string of DNA as an input sequence GGATGGATG, apply the simple
regex "GGATG" as in
Regex r = new Regex("GGATG", (RegexOptions.Compiled));
MatchCollection matches = r.Matches("GGATGGATG");
Now I would expect to get two matches right? One at index 0 in the
|
by: Trev |
last post by:
Hi,
If I had a string denoted by MyArray, how would I extract the number
in brackets for use in the programme later on? I've tried "\"
but all I get is a syntax error. What would be the usage for
using the number in the programme (so that I can check if the index is
within bounds)?
Talking of groupings, if I had a string like MyRef.MyArray.MyVal how
would I extract the strings
into an array for processing, so that Array = MyRef, Array =
|
by: jonnyboy6969 |
last post by:
Hi All
Really hoping someone can help me out here with my deficient regex skills :)
I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose is that I seek out terms which are in a glossary on our site, and automatically link to this definition. Its slightly complex becase certain elements have to be ignored, for exampleI dont want to add links within existing links, or for example link...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |