Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Count the a's

  • 31-10-2000 4:44pm
    #1
    Registered Users, Registered Users 2 Posts: 6,265 ✭✭✭


    lo,
    i've got a string of test
    eg asdkjalvuahlrkvavlkab
    and i want to count the number of each letters. any one got any idea how to do this?

    thanx
    MiCr0
    btw i've only got excel and regular windows s/w,

    [This message has been edited by MiCr0 (edited 31-10-2000).]


Comments

  • Registered Users, Registered Users 2 Posts: 432 ✭✭Catch_22


    i mailed ya a cuple of lines of perl to do it,
    dunno if thats standard windows sware, but then thats your fault for using windows :P

    l8r

    c22


  • Registered Users, Registered Users 2 Posts: 20,099 ✭✭✭✭WhiteWashMan


    easy, theres 5 a's in that string of text


  • Registered Users, Registered Users 2 Posts: 6,265 ✭✭✭MiCr0


    ok smartass
    count and index all the letters in
    qfoukwucpujlukfdsjfdoujoswubepswsbipnqnjqfou
    ksdlnepsaipuoujosdqfzwuobsqubqsjfdnbbukobsqf
    kfhjubskhflskcfjwnkofkwuyshsbnudbsbpomswshsk
    sblfkyshfdswfkwuwubtndhsdfofdksdejuuducneskp
    ofjhslsosjcukngujfujsdopsljfgpdsbukxlpqfipuk
    popchnjopsdwfbskukljubbskobsqsdjuyfduksbseps
    ejnkopsdwfbfkujsbukkpudsdqujfdnoskwusbmubnqf
    oukwucpujlukfdsjfdoujoswubepswsbipnqnj
    in order of frequency

    dogbert.gif
    It’s so easy to criticise


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Without knowing any excel code,

    1. Step through the string one character at a time.

    2. Capitalise the character and get the ASC value of the character.

    3. Take away 64 from it ("A" = 65 ASCII)

    4. Increment the value of A:x where x is the value you got.

    When it's finished all the cells in A column should give you the count. If you want to work out upper and lower then you'll have to work that out yourself.

    ... This post should also be in the Programming forum.


    [This message has been edited by Hobbes (edited 31-10-2000).]


  • Registered Users, Registered Users 2 Posts: 20,099 ✭✭✭✭WhiteWashMan



    what he said...
    duh!


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 6,265 ✭✭✭MiCr0


    in the end i just counted, as the wise wwman said.
    thanx any way

    btw hobbes, i've no idea what your system does, but i'll have another look - ta


  • Registered Users, Registered Users 2 Posts: 20,099 ✭✭✭✭WhiteWashMan


    roflmbo
    ahhh micro, youre a good lad. even if you live in a very cold country!


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Mine does more then it should. If it's just the letter "a" (not "A") then just do the following.

    at Dos prompt type.

    C:\>QBASIC
    open "textfile.txt" for input as #1
    TotalACount = 0
    do while not eof(1)
     line input #1, a$
    [b] x = instr(a$,"a")
     do while x <> 0
       TotalACount = TotalACount + 1
       x = instr(x+1, a$,"a") ' Might be x instead of x+1 can't remember.
     loop[/b]
    loop
    close #1
    Print "Total of letter 'a' = ";TotalACount
    

    The bit in bold I'm doing instead of...
    For n = 1 to len(a$)
    if mid$(a$,n,1) = "a" Then TotalACount = TotalACount + 1
    Next n


    The reason being the INSTR is a faster search method then FOR NEXT loop.

    Now this is assuming that your file is actually made up of lines of strings instead of just a straight run of characters (in which case you'll get an error). You will have to open the file as binary then.


  • Registered Users, Registered Users 2 Posts: 6,265 ✭✭✭MiCr0


    hobbes (simon is it?)
    you are truely wise in the ways of loops

    /me bows to you

    MiCr0


  • Registered Users, Registered Users 2 Posts: 6,265 ✭✭✭MiCr0


    atm wwman its lovely and sunny and quiet warm smile.gif

    which is nice!


  • Advertisement
Advertisement