DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2005

    Check duplicated characters in a String


    Assume that I have a String and I want to check whether there is one (or more)
    character that appear more than once in that String. How should I do that? I'm a bit stuck at the algorithm. Please help.


  2. #2
    Join Date
    Jul 2005
    SW MO, USA
    An algorithm:
    Use a hashtable to save key=char, value = count
    Loop thru length of string
    Get next char from the string
    Look in hashtable for the char
    If not found, create a new entry for that char with value = 1
    if found, increment value by 1
    end loop
    get keys from hashtable and retrieve values

  3. #3
    Join Date
    Sep 2005
    //start for or while loop, and nest another on inside
    for(int i = 0; i < stringName.length(); i++) {
        for(int j = 0; j <stringName.length(); j++) {
             /*compare the character srting's character position i with j using .charAt(int place) method, if they are the same add 1 to a counter. At the end of the for(j) loop decide if the counter is above 2. if it is then you have a repeated letter */
            if(compare two characters at i and j in stringName and check if same) {
                  add one to a counter;
          if(counter > 1) {
             do what you want to do once you have found two of the same characters in the same string.
    I prefer to live in my own shadow. At least then I can be compared to a false past I'm more familiar with

Similar Threads

  1. replacing characters in string
    By Reuben in forum Enterprise
    Replies: 1
    Last Post: 10-26-2000, 02:43 AM
  2. Please help me -- urgent -- deadlock error
    By chandra in forum VB Classic
    Replies: 0
    Last Post: 06-22-2000, 07:36 AM
  3. Replies: 0
    Last Post: 06-22-2000, 07:30 AM
  4. NetUserEnum Api
    By Mike in forum VB Classic
    Replies: 0
    Last Post: 04-24-2000, 03:05 PM
  5. Database problems
    By Robert Rieth in forum VB Classic
    Replies: 1
    Last Post: 04-11-2000, 03:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.