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

char comparison

how to compare the words in array?
for example
var words[1] = "blue"

var words[2] = "eulb"

var words[3] = "purple"


How we find out that eulb and blue has same length and letters ? whereas elube doesnt have same length and letters . thanks
Mar 27 '07 #1
1 1505
dorinbogdan
839 Expert 512MB
Try this function (it is case insensitive):
Expand|Select|Wrap|Line Numbers
  1. function Compare(str1, str2){
  2.     var i = 0;
  3.     var regex = null;
  4.     var count1 = 0, count2 = 0;
  5.     if (str1.length != str2.length) return false;
  6.     for (i=0;i<str1.length;i++){
  7.         regex = new RegExp(str1.charAt[i],'g');
  8.         count1 = str1.replace(regex,"").length;
  9.         count2 = str2.replace(regex,"").length;
  10.         if (count1 != count2) return false;
  11.     }
  12.     return true;
  13. }
  14.  
It returns true if str1 and str2 have same length and contain same letters (and the same number of occurrences), otherwise false.
Mar 27 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Rob Smeets | last post by:
Hi all, I have the following problem: I have to revise a c++ dll. And i'm new to c++. I have to change a function, but i cannot change it's structure. I want to check the parameters and act...
0
by: g | last post by:
Hi all. Maybe this question has been asked many times before, but I was not able to find any pointer. I apologize in advance, for it refers to a particular standard library implementation (GNU...
2
by: Neil Zanella | last post by:
Hello, Consider the following program. There are two C style string stack variables and one C style string heap variable. The compiler may or may not optimize the space taken up by the two stack...
5
by: twkelsey | last post by:
Hi, My company has a scenario where we would like to change the data type of an existing primary key from an integer to a char, but we are concerned about the performance implications of doing...
3
by: Vishal Ladha | last post by:
Hi ! I have been experimenting with char * for a while now. I have two pieces of code : Code1 : ===== char *ptr = "hello";
20
by: Jacky Cheung | last post by:
Hi, I am developing a vCard application which have to support UTF-8. Does the UTF-8 in char* will crash the strlen, I mean does UTF-8 have some char which treat as NULL character in strlen? ...
11
by: Jason Curl | last post by:
Dear C people, C90 doesn't specify if 'char' is either 'signed char' or 'unsigned char' leaving it to the implementation of the compiler. Has this changed for C99, or is it still the same? ...
74
by: aruna.mysore | last post by:
Hi all, I have a simple definitioin in a C file something like this. main() { char a; ....... int k; }
10
by: william | last post by:
#include <stdio.h> int main() { char *str=NULL; char x="today is good!"; printf("%s", str); str=strtok(x," "); if (str=="today") //<==here is line that confuses me printf("they equals!\n");
33
by: Michael B Allen | last post by:
Hello, Early on I decided that all text (what most people call "strings" ) in my code would be unsigned char *. The reasoning is that the elements of these arrays are decidedly not signed. In...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.