+ Reply to Thread
Results 1 to 4 of 4

Count unique characters in a string

  1. #1
    Registered User
    Join Date
    07-25-2007
    Posts
    2

    Count unique characters in a string

    Hi all,
    Does anyone know how to count the number of unique characters in a particular cell?
    ie if I have "AFDED" in a cell - I would like to see the length of the string as 4 (rather than 5 - as you would get from the "len" function).

    Thanks very much.

    yelk

  2. #2
    Forum Contributor Lotus123's Avatar
    Join Date
    11-07-2005
    Location
    Texas
    MS-Off Ver
    2007
    Posts
    153
    I'll be interested to see if someone can come up with a better solution, but this is what I drew up after reading the question...presuming the value to be examined is in cell A1:

    =SUM(IF((LEN(A1)-LEN(SUBSTITUTE(A1,{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8","9","0"},""))),1,0))

    The advantage of the above is you can be specific about characters to count....for example, the above ignores spaces.

    I'm sure there are other ways to do this, but maybe this will work just fine.

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    This formula will count 1 instance of any character, spaces, punctuation letters etc. It's case-sensitive so although

    AFDED

    will give a count of 4

    AbB %Yy = 7

    BBB 6 =3

    =COUNT(1/FREQUENCY(CODE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)),ROW(INDIRECT("1:255"))))

    confirmed with CTRL+SHIFT+ENTER

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    or amending Lotus123's approach

    =SUM(IF((LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(ROW(INDIRECT("1:255"))),""))),1,0))

    also confirmed with CTRL+SHIFT+ENTER

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1