473,396 Members | 1,895 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,396 software developers and data experts.

how do i find a string between 2 delimiters please

hello

I am a trying to find the text between a ? mark and an = sign:
var theData;
var begin;
var thePageNo;
var beginFrom;
beginFrom = top.location.href.indexOf("=");
begin = top.location.href.indexOf("?");
if (begin > 0 )
{
theData = top.location.href.substring(begin+1,location.href. length);
theData = unescape(theData);
..........
--
what I need to do is pass the filename without the + sign and whatever
follows it.

So if the string passed is:
http://philippeoget.50megs.com/?IT_S...rmation.htm=13

I want to be able retrieve only the string up and including the = sign.
ie.: http://philippeoget.50megs.com/?IT_S...nformation.htm

I tried:
theData = top.location.href.substring(begin+1,location.href. length-beginFrom);

but it doesn't like it..

TIA
Regards

Phil
Jul 23 '05 #1
5 3365
In article <f6**************************@posting.google.com >,
ph**********@yahoo.com enlightened us with...
hello

I am a trying to find the text between a ? mark and an = sign:
var theData;
var begin;
var thePageNo;
var beginFrom;
beginFrom = top.location.href.indexOf("=");
begin = top.location.href.indexOf("?");
if (begin > 0 )
{
theData = top.location.href.substring(begin+1,location.href. length);
theData = unescape(theData);
.........


This worked for me. It's extensible so the URL can have more params. It
assumes the one you want is the first part of the first pair ([0]).

<html>
<head>
<title> New Document </title>
</head>

<body>
<script language="javascript" type="text/javascript">
// split the query string into param=val pieces
var qs = location.search.substr(location.search.indexOf("?" )+1);
var pieces = qs.split("&"); // pieces has all the name/value pairs

var piece = null;
if (typeof pieces[0] != "undefined") piece = pieces[0].split("="); //
piece has individual name/values for pieces[0]

if (typeof piece[0] != "undefined") url = self.location.href+piece[0];
alert(url);
</script>
</body>
</html>

--
--
~kaeli~
Shotgun wedding: A case of wife or death.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2


Regards

Philippe
http://uk.geocities.com/philippeoget/

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3
<snip>
So if the string passed is:
http://philippeoget.50megs.com/?IT_S...rmation.htm=13

I want to be able retrieve only the string up and including the = sign.
ie.: http://philippeoget.50megs.com/?IT_S...nformation.htm

I tried:
theData = top.location.href.substring(begin+1,location.href. length-beginFrom);

but it doesn't like it..

TIA
Regards

Phil


The easiest way to do this is with a regular expression.

I just wrote and tested this:

var someString =
'http://philippeoget.50megs.com/?IT_Study___Information.htm=13';

document.write(someString + '<br/>');
someString = someString.replace(/^.*\?(.*)=.*$/, '$1');
document.write(someString + '<br/>');

Shawn
Jul 23 '05 #4
Phil,

Although my last post provided a working solution,
I realized that there is a flaw in my logic. I was
assuming that only one name/value pair will ever
be passed in the querystring. Please see below
for a correction.

For regex (regular expression) info, this
book is the best source:
http://www.oreilly.com/catalog/regex2/

Shawn


var someString =
'http://philippeoget.50megs.com/?IT_Study___Information.htm=13';

//altered to further illustrate regex
someString =
'http://philippeoget.50megs.com/?IT_Study___Information.htm=13&lang=en';
//show original string
document.write(someString + '<br/>');

//perform replace
someString = someString.replace(/^.*\?(.*)=.*$/, '$1');

//show altered string
document.write(someString + '<br/>');
//
someString = '';
//someString = 'http://www.abc.com?page=it_study&lang=en';

//Note, this regex will work when there are more parameteres
//in the querystring than just one. The other one will not.
//Example:
http://philippeoget.50megs.com/?IT_S...htm=13&lang=en
//The previous regex will return:
IT_Study___Information.htm=13&lang
//This one will return: IT_Study___Information.htm

someString = someString.replace(/^.*\?([^=]*)=.*$/, '$1');
document.write(someString + '<br/>');
Jul 23 '05 #5
Thank you very much for your help.

Regards

Philippe
http://uk.geocities.com/philippeoget/

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #6

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

Similar topics

3
by: Justin L. Kennedy | last post by:
I am looking for a function that takes in a string and splits it using a list of other strings (delimiters) and can return the delimiters as well as the extra parts of the string. I was trying the...
4
by: Prabhu | last post by:
Hi, We are having problem in converting a byte array to string, The byte array has char(174), char(175), char(240), char(242) and char(247) as delimiters for the message. when we use...
5
by: kurt sune | last post by:
The code: Dim aLine As String = "cat" & vbNewLine & "dog" & vbNewLine & "fox" & vbNewLine Dim csvColumns1 As String() = aLine.Split(vbNewLine, vbCr, vbLf) Dim csvColumns2 As String() =...
16
by: Amit Gupta | last post by:
Hi - I get a seg-fault when I compile and run this simple program. (seg-fault in first call to strtok). Any clues? My gcc is "gcc version 4.1.1 20070105 (Red Hat 4.1.1-51)" #include...
1
by: vang | last post by:
How do I find out which delimiter if found/used when splitting a string with multiple delimiters are defined in a char array? Example: dim i as integer dim returnText as string dim InputText...
4
by: nnguyec | last post by:
Hi, I'm trying to write a small code for an assignment which the void String Tokenizer will get a line input, and take out those delimiters from the original string. Then pass each string without the...
11
by: Lothar Behrens | last post by:
Hi, I have selected strtok to be used in my string replacement function. But I lost the last token, if there is one. This string would be replaced select "name", "vorname", "userid",...
11
by: ramu | last post by:
Hi, Suppose I have a string like this: "I have a string \"and a inner string\\\" I want to remove space in this string but not in the inner string" In the above string I have to remove...
5
by: alex21 | last post by:
I am trying to write a function for determining the data type of columns in a delimited file. However my function is not detecting a newline and exiting the loop after the end of the first line. ...
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
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...
0
agi2029
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,...

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.