Hi all,
I am using "match" to see if elements in one array match elements in another array.
My first array is "1.1,1.2,2. 1" so I convert it to a string. Next, I have a loop that cycles through the second array, converts the current element of the second array to a string, and then uses "match" to see if this occurs in the string corresponding to the first array.
"match" seems to get confused if I have an element such as "2.2" in the second array, as it thinks it matches "....2,2... ." in the string corresponding to the first array.
Any ideas on how to fix this?
Thanks in advance
7 1706 acoder 16,027
Recognized Expert Moderator MVP
Why bother with strings when you have the values and can match directly?
When using match, the string is converted to a regular expression where the dot character can match any character including comma.
Thanks for the reply.
I thought it would be quicker using "match" with string than having a subloop (for each element within array 2) within a loop (for each element within array 1).
Am I misunderstandin g your suggestion?
Thanks!
acoder 16,027
Recognized Expert Moderator MVP
Fair enough, though I'm not sure about the exact performance differences.
For your problem, replace the "." with "\.", so 2.2 becomes 2\.2, so that the dot is matched and not any character.
Thanks for the reply.
In the end, my work around was to change "string.split(' ,')" to "string.split(' X')".
EDIT: Oops, that doesn't work!
Thanks again!
acoder 16,027
Recognized Expert Moderator MVP
Why would you be using split (producing an array) when you already had one in the first place?!
As I said, use the backslash \ to escape the dot.
Sorry, hadn't looked at it until last night and forgot where I was!
The problem with your suggestion in that I'd have to edit a lot of other functions (each element is called from a cell ID in a table).
The correct work around is: string1 = string.replace(/,/g, "XXX")
Works for me so far.
acoder 16,027
Recognized Expert Moderator MVP
That would work, but be careful about the fact that it's a fix because the dot is still matching any character. It doesn't match 2,2 because that's now become 2XXX2.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: kmunderwood |
last post by:
I am trying to combine "if match=" and "when test"
I am a newbie, and have made both work separately, but I can not seem
to combine them.
This is my xml("index.xml")page(I can not change this, it comes to me
this way.
<?xml version="1.0" encoding="iso-8859-1" ?>
|
by: Chris Mantoulidis |
last post by:
I was wondering if there was something like a "match" class in the
std. By match class I mean something like a search tool. That is I
will tell it in what text to search and WHAT to search for. The format
of what I want it to find would be something like:
"abc?efg*mnopq?st*z"
I hope you understand what I mean. :)
So it a class (or anyway SOMETHING) in the std header files that is
something like that or do I have to implement it myself?
|
by: myth.drannon |
last post by:
Hi ,
I'm trying to find a simple solution to this question.. ( not just
making two match parts)
I have
<xsl:template match=" one | two " >
and then I want to test what match I have and do something accordinly.
I was thinking <xsl:if test="match=one" > will work but it's not ....
|
by: Licheng Fang |
last post by:
Basically, the problem is this:
'do'
Python's NFA regexp engine trys only the first option, and happily
rests on that. There's another example:
'oneself'
The Python regular expression engine doesn't exaust all the
|
by: Papkin |
last post by:
Hi
if ( eregi("^/a-zA-Z0-9±ęćłń󶿼ˇĆĘŁŃÓ¦¬Ż\.\/\/-]{2,65}$","Merry
& Cat") )
return true;
else
return false;
I'd like to match also "&" but this regexp above does not do this, adding \&
does not help. Any ideas?
| |
by: Pythor |
last post by:
OK I'm trying to create a sql query on our as400. I have a main table
like this:
acct prf acct no. sku
AAA 123 ABCD
AAA 123 XYZ
I have another table
|
by: Good Man |
last post by:
Hi there
Ideally, I'd like to create one javascript function and pass the file
extension i'm looking for to see if its there:
<input type="file" onchange="checkFile('pdf',this)" />
and then have the function something like (w/ Prototype)
|
by: patelxxx |
last post by:
Hi Guy's,
I'm getting the error: "Username or password did not match" BEFORE I even enter a username and password, can someone help?
1) The site I'm accessing is: http://www.valuemapping.co.uk/VMSE/
2) Then I click/select the following application: "VMSE Reporting" and get the above error.
The CGI script for this is:
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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: 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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
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...
| |