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

anagram checker wont work ...

im trying to make a program thats supposed to check whether 2 strings are anagrams of each other (anagram = same letters in both strings, but in different orders... "cool as wet art" , and "cs at waterloo" for example).


Expand|Select|Wrap|Line Numbers
  1. while (str2.get_Length() != 0)   //<---- checks whether second string is "cleared"
  2.         {
  3.  
  4.                        //loop, from start of string (k = 0) to end of string (length2)                      for (k = 0; k <= length2; k = k + 1)
  5.             {
  6.                 char1 = str1.charAt(0); 
  7.                 y = 0;   resets y
  8.                 char2 = str2.charAt(0);  
  9.                 if (char2 == char1) //checks if two are the same, if they are, makes y = point in string with char 2
  10.                                 {
  11.                         y = str2.IndexOf(char2);
  12.                                 }            
  13.  
  14.                                  if (y > -1) //checks if y is positive, if so, takes a substring of all other letters
  15.                         str2 = (str2.substring(0, y)) + (str2.substring(y + 1));
  16.             }
  17.  
  18.  
  19.         }  
can anyone figure out why it wont work???
Nov 3 '07 #1
2 2562
Ganon11
3,652 Expert 2GB
Well, two things:

1) If char1 and char2 are the same character, then the IndexOf function will always return 0, because that character is the first character. If they aren't equal, you don't do anything to get the index of that character.

2) You don't have anything returning false if the two Strings are not anagrams of each other.
Nov 3 '07 #2
JosAH
11,448 Expert 8TB
Sort both strings and check whether or not both sorted strings are equal, e.g. both
strings "baa" and "aba" sorted are equal to "aab".

kind regards,

Jos
Nov 3 '07 #3

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

Similar topics

1
by: DK15798 | last post by:
Anybody think there is a way to solve the anagram problem (reading in a dictionary of words and printing out the anagrams for all words) with an open address hash table as opposed to a chained hash...
7
by: Hank Reed | last post by:
I am trying to use the spell checker on an unbound control in Access 2000. I run the checker in the AfterUpdate event of the control. After the spell checker is done, I get the following message:...
8
by: Joe | last post by:
Hello All: Does anyone know of a spell checker that works with .NET? Any options will be welcome. TIA, -- Joe
13
by: kolmogolov | last post by:
/* Hi, I have removed things irrelevant to reproducing the problem. What's wrong with my code? Thanks in advance for any hint! 1166425362 */ #include <stdio.h> #include <stdlib.h> #include...
6
by: Neil | last post by:
Is there way to have control over the MS-Access spell checking (besides just launching it)? We want to tell it to check all records, but skip certain fields (or, alternatively, ONLY check certain...
1
by: heloworld | last post by:
hi buddies.... i don ve any idea as how to solve an anagram problem... plz help me out....
19
by: dave | last post by:
Hi All, I wrote a program that takes a string sequence and finds all the words inside a text file (one word per line) and prints them: def anagfind(letters): #find anagrams of these letters...
3
by: Mike | last post by:
I have an app running at a client where, when the spell checker is supposed to run, it reports "Can't start spell checker because it is not installed". I have never had this before - it works...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: 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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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.