Count maximum occurance of charecter in a string

HI all
I want to know how to count the maximum number of occurrences of a character in a string
for Eg String s = "aaabbccccccdddeeee" , here in this string the maximum occurrences charcter is "c" and its count is 5

anilrp wrote:
I want to know how to count the maximum number of occurrences of a character in a string
for Eg String s = "aaabbccccccdddeeee" , here in this string the maximum occurrences charcter is "c" and its count is 5How did you do it manually (mentally)?
Unless you are rainman I am guessing you
counted the occurrences of each character
then found the largest count.
Do the same in your program.

Similar Messages

  • Count the occurance of a character in a string

    What is the function to count the occurance of a character in a string.
    like 'test test1 test2 test3' with in this string there are 3 white spaces.
    instr will give the first one, replace will change the all... and what's for the occurance (number of white spaces, which is 3 in this case) count
    Message was edited by:
    gladnn

    SQL> var a varchar2(25)
    SQL> exec :a := 'gghhhh999jjjj'
    &nbsp
    PL/SQL procedure successfully completed.
    &nbsp
    SQL> select length(:a) - nvl(length(replace(:a,'h','')),0) from dual;
    &nbsp
    LENGTH(:A)-NVL(LENGTH(REPLACE(:A,'H','')),0)
                                               4Rgds.

  • [Question]how to count the occurance of numbers inside the array

    im just practicing my java skill but i cant get my program work can you give me guys some idea on how to determine a number that occured more than 1 inside the array e.g i have 10 elements and inside of my offset i have
    1,2,5,4,5,6,5,8,9,5
    and what im planning to do is count the occurances of the number who occures more than 1 and for that 5 occur 3 times how my program can know that i use for loop but cant figure out how to filter the occurances of numbers inside
    my offset
    thank's

    Encephalopathic you said put - 1 instead i did - 2
    public class sample
       public static void main(String args[])
          int num[] = {2,2,2};
          int index1, count = 0, find = 0;
          for(index1 = 0; index1 < num.length - 2; index1++)
             for(int index2 = 0; index2 < num.length; index2++)
                if(num[index2]==num[index1])
                  find = num[index2];
                  count++;
             System.out.println("i found " + find + " " + count + " same number inside your offset");
    }output is:
    i found 2 3 same number inside your offset
    but another question is what if i want my program to tell the other number that occur 1 time
    like this:
    i found 1 2 same number inside your offset
    i found 2 0 same number inside your offset
    i found 1 2 same number inside your offset

  • ORA-00604:error occurred at recursive SQL level string

    Hi all,
    Oracle Version :- 11.2.0.2
                   I found a error in a trigger(Statement Level)
    ORA-00604:error occurred at recursive SQL level string.
    Before Finding this issue,Once the DB Response was slow . Will this be the issue Of DB Slow response. The Above trigger fires for each entry in an transaction table.
    The code is Patched and was executed . The above issue was found during another issue and not the DB Slow response.
    My Doubt is Whether DB response slow issuewould be because of this. Now after fixing this Slow response was not reported.
    Your inputs are highly appreciated.

    it helps if you can post the complete stack of error messages (I'm suspecting you have several more messages than just ORA-00604).
    A cut-n-paste of the SQL*Plus session with the SQL statement and the error message(s) below would give the info as to what the actual problem is.
    Do you have INSERT priv. on that table? Are you doing this from within a stored procedure or at SQL prompt?

  • How i can count the number of words in a string?

    hi, i want to know how to count the number of words in a string
    e.g. java is a very powerful computer language.
    i will get 7 words.
    thanks in advance..

    Jverd, this has actually been answered, but due to an
    attack of goldie-itis, all the answers were hosed.
    The OP did get an answer, though.Yeah, I know. I just didn't know if he saw the answer before it went away.

  • Count the number of occurrence in a string

    is there any api for counting the number of occurrence in a string or should i write a method myself?
    for example. I want to count "." in "1.2.3.4.". i want to count the dot in this string.
    I am just wondering.
    Thanks in advance.

    is there any api for counting the number of
    occurrence in a string or should i write a method
    myself?The latter.

  • How to add extra per day records based on maximum occurances in the week.

    Hello,
    I need to add extra records based on maximum occurances on a day in a week.
    For example, the result of the query shows that maximum occuances in a week 0 is 3 on so I need to add empty records in each day in that week.
    SQL QUERY:
    with  numbers as (
    SELECT ROWNUM N FROM dual 
      CONNECT BY LEVEL <=35
    ),months as (
    SELECT     ADD_MONTHS('01-JUN-10',n-1) AS current_month,
         TO_CHAR(ADD_MONTHS('01-JUN-10',n-1),'fmMonth-YYYY') AS current_month_label
    FROM numbers
    WHERE ADD_MONTHS('01-JUN-10',n-1) <= NVL(add_months('01-JUN-10', :monthcount-1),:p_month)
    ORDER BY n ASC
    ) , dates as (
    select     trunc(trunc(m.current_month, 'MM'), 'D') + n - 1 calendar_date,
         trunc((n - 1) / 7) AS week_num,
                    m.current_month as current_month
    from     numbers, months m
    where trunc(dom.schedule.calendar_begin(m.current_month) + n - 1, 'd') <= last_day(m.current_month)
    Order By week_num, calendar_date
    select dates.week_num, edate, name from (
    --week 0
    select '30-MAY-10' as edate, 'JJ' as name from dual union
    select  '31-MAY-10' as edate, 'MK' as name from dual union
    select  '01-JUN-10' as edate, 'MK' as name from dual union
    select  '01-JUN-10' as edate, 'BK' as name from dual union
    select  '01-JUN-10' as edate, 'JJ' as name from dual union
    select  '04-JUN-10' as edate, 'KK' as name from dual union
    select  '04-JUN-10' as edate, 'LA' as name from dual      union
    -- week 1
    select  '06-JUN-10' as edate, 'BK' as name from dual union
    select  '06-JUN-10' as edate, 'JJ' as name from dual union
    select  '07-JUN-10' as edate, 'KK' as name from dual union
    select  '11-JUN-10' as edate, 'LA' as name from dual      
    ) a  join dates on dates.calendar_date = a.edate   
    order by week_num, to_date(edate);CURRENT RESULT :
    WEEK_NUM             EDATE                NAME
    0                   30-MAY-10            JJ
    0                   31-MAY-10             MK
    0                   01-JUN-10             MK
    0                   01-JUN-10             JJ
    0                   01-JUN-10             BK
    0                   04-JUN-10             KK
    0                   04-JUN-10             LA
    1                   06-JUN-10             BK
    1                   06-JUN-10             JJ
    1                   07-JUN-10             KK
    1                   11-JUN-10             LAREQUIRED RESULT:
    WEEK_NUM             EDATE                NAME
    0                   30-MAY-10             JJ
    0                   30-MAY-10            null
    0                   30-MAY-10            null
    0                   31-MAY-10            MK
    0                   31-MAY-10            null
    0                   31-MAY-10            null
    0                   01-JUN-10             BK
    0                   01-JUN-10              JJ
    0                   01-JUN-10             MK
    0                   02-JUN-10             null
    0                   02-JUN-10             null
    0                   02-JUN-10             null
    0                   03-JUN-10             null
    0                   03-JUN-10             null
    0                   03-JUN-10             null
    0                   04-JUN-10             KK
    0                   04-JUN-10             LA
    0                   04-JUN-10             null
    0                   05-JUN-10             null
    0                   05-JUN-10             null
    0                   05-JUN-10             null
    --Number of Week 1 records should be 14 = (max occurances on 06-JUN-10)  * 7
    1                   06-JUN-10             BK
    1                   06-JUN-10             JJ
    1                   07-JUN-10             KK
    1                   07-JUN-10             null
    1                   08-JUN-10             null
    1                   08-JUN-10             null
    1                   09-JUN-10             null
    1                   09-JUN-10             null
    1                   10-JUN-10             null
    1                   10-JUN-10             null
    1                   11-JUN-10             LA
    1                   11-JUN-10             null
    1                   12-JUN-10             null
    1                   12-JUN-10             nullI would appreciate it if you could help me to find efficient way to achieve this?
    Thanks,
    GM
    Edited by: user12068331 on Sep 28, 2010 2:17 PM
    Edited by: user12068331 on Sep 28, 2010 2:48 PM

    Ok,
    Few things to clarify first :
    1 - How do you define week number ?
    Oracle has 2 different way for week number : normal week number (WW) and isoweek (IW).
    is your weeknumber one of those, or is it something else ?
    2 - Depending on the country the week doesn't start on the same day : in France (as most of Europe I think) first day is monday, where in the USA (as far as I know) first day is sunday.
    the to_char builtin function can display weeknumber :with a as (
    --week 0
    select 0 as weeknum, to_date('30-MAY-2010','DD-MON-YYYY') as edate, 'JJ' as name from dual union all
    select 0 as weeknum, to_date('31-MAY-2010','DD-MON-YYYY') as edate, 'MK' as name from dual union all
    select 0 as weeknum, to_date('01-JUN-2010','DD-MON-YYYY') as edate, 'MK' as name from dual union all
    select 0 as weeknum, to_date('01-JUN-2010','DD-MON-YYYY') as edate, 'BK' as name from dual union all
    select 0 as weeknum, to_date('01-JUN-2010','DD-MON-YYYY') as edate, 'JJ' as name from dual union all
    select 0 as weeknum, to_date('04-JUN-2010','DD-MON-YYYY') as edate, 'KK' as name from dual union all
    select 0 as weeknum, to_date('04-JUN-2010','DD-MON-YYYY') as edate, 'LA' as name from dual union all
    -- week 1
    select 1 as weeknum, to_date('06-JUN-2010','DD-MON-YYYY') as edate, 'BK' as name from dual union all
    select 1 as weeknum, to_date('06-JUN-2010','DD-MON-YYYY') as edate, 'JJ' as name from dual union all
    select 1 as weeknum, to_date('07-JUN-2010','DD-MON-YYYY') as edate, 'KK' as name from dual union all
    select 1 as weeknum, to_date('11-JUN-2010','DD-MON-YYYY') as edate, 'LA' as name from dual
    select to_char(a.edate,'IW') isoweek, to_char(a.edate,'WW') numweek, a.*
    from a;
    IS NU    WEEKNUM EDATE                          NA
    21 22          0 Sunday    30/05/2010 00:00:00  JJ
    22 22          0 Monday    31/05/2010 00:00:00  MK
    22 22          0 Tuesday   01/06/2010 00:00:00  MK
    22 22          0 Tuesday   01/06/2010 00:00:00  BK
    22 22          0 Tuesday   01/06/2010 00:00:00  JJ
    22 23          0 Friday    04/06/2010 00:00:00  KK
    22 23          0 Friday    04/06/2010 00:00:00  LA
    22 23          1 Sunday    06/06/2010 00:00:00  BK
    22 23          1 Sunday    06/06/2010 00:00:00  JJ
    23 23          1 Monday    07/06/2010 00:00:00  KK
    23 24          1 Friday    11/06/2010 00:00:00  LA
    11 rows selected.

  • How do count how many 'A' s in this string using sql stmt?

    hi all,
    i have a string like 'AAAAARAMAAAAKRISHNAAAA'.
    in this ,i want to find out how many 'A's .
    how do find out this using select stmt.

    (length(s) - nvl(length(replace(s, 'A')), 0)) / length('A')but consider (by modifying the question slightly to "how do count how many 'AA' s in this string using sql stmt? ")
    SQL>  select (length('AAAAARAMAAAAKRISHNAAAA') - nvl(length(replace('AAAAARAMAAAAKRISHNAAAA', 'AA')), 0)) / length('AA') x from dual
             X
             6
    1 row selected.couldn't I argue that the result should be 10 as e.g. in
    SQL>  select * from xmltable('let $str := "AAAAARAMAAAAKRISHNAAAA"
                            let $search := "AA"
                            for $i in 1 to string-length($str)
                              where substring($str, $i, string-length($search)) = $search
                              return substring($str, $i, string-length($search))' columns x varchar2(10) path '.')
    X        
    AA       
    AA       
    AA       
    AA       
    AA       
    AA       
    AA       
    AA       
    AA       
    AA       
    10 rows selected.Matter of definition I suppose .... ;)
    btw. regexp_count also yields 6:
    SQL>  select regexp_count('AAAAARAMAAAAKRISHNAAAA', 'AA') x from dual
             X
             6
    1 row selected.

  • Include '\' escape charecter in normal String

    I just want to include in \ charecter in a string
    like "please divide 1000/100 when you do this"
    but is not allowing me .Please help me out thanks.

    you need to escape the escape. ie
    System.out.println("600 \\ 3" );
    will display as
    600 \ 3

  • Counting errors occured in personnel number (0HR_PT_2)

    When loading data in BW with extractor 0HR_PT_2 we find the following message in the applicationlog:
    'counting errors occured in personnel number....'
    This problem causes the upload in BW to 'hang'in yellow status and the administrator must manually start the next staging (-> ODS en --> cube)
    What also strikes as a bit strange is that the personnel-number in question doesn't belong to the selected CO-area in the infopackage
    Anyone a clue?
    Lex Meijerink

    Hi,
    I've found this note that might be helpfull for us.
    Note 800049:
    Summary
    Symptom
    You are using time management datasources 0HR_PT_1/2/3 for extracting data from R/3. During extraction the message 023 from the message class HRTIM00DW may occur in the protocol. This is an application warning message explaining that the error happened in the application processing part of extraction. This problem should be corrected through changing the application customizing appropriately.
    If you want to change the category of this message from "warning" to "information", please implement the correction instruction from this note. This correction is a modification and the change will not be delivered with the next service package and is not in the standard. Therefore, please implement the correction instruction manually. If in the future you want the message category to be changed back to "warning" then please take the change back.
    Other terms
    0HR_PT_1, HRTIM00DW 023, 023, 0HR_PT_2, 0HR_PT_3
    Reason and Prerequisites
    Modification
    Solution
    Please implement the correction instruction manually. If in the future you want the message category to be changed back to "warning" then please take the change back.
    David

  • How to count the occurance of the data entry on OBIEE answers

    Hello guys
    I have one report that contains a column call type. In the report that I am creating, there are 200 rows in that column, but there are really just 4 types of call type; "A,B,C,D"
    So in my report it looks like this
    Call type other dim and fact
    A
    A
    A
    B
    B
    C
    D
    D
    D
    D
    Now I need to add one more column said call counts, which needs to count the occurance of each call types:
    Call type count others
    A 3
    B 2
    C 1
    D 4
    So how would I be able to achieve this on answers? I used "count" function on "count" column, but it is counting all the rows without distinguishing the call type
    Please let me know
    Thanks

    Hi,
    Looks to me like this should be a measure within the RPD rather than something you try to do at the presentation level. Any simple "# of <x>" measure will work like you describe, it should just do a simple count on something unique in the table and have an aggregation rule set, OBIEE will then automatically group by this in your report by distinct call type without you having to do anything complex.
    Regards,
    Matt

  • A quick way to count the number of  newlines '/n' in string of 200 chars

    I am trying to establish the number of lines that a string will generate.
    I can do this by counting the number of '/n' in the string. However my brute force method (shown below) is very slow.
    Normally this would not be a problem on a 2800mhz Athlon (Standard) PC this takes < 1 second. However this code resides within a speed critical loop (not shown). The code shown below is a Achilles heal as far as the performance of this speed critical loop goes.
    Can anyone suggest a faster way to count the number of �/n� (new lines) within a text string of around 50- 1000 chars, given that there may be 10 � 100 newline chars. Speed is a very important factor for this part of my program.
    Thanks in advance
    Andrew.
        int lineCount =0;
        String txt = this.getText();
        //loop throught text and count the carridge returns
        for (int i = 0; i < txt.length(); i++)
          char ch = txt.charAt(i);
          if (ch == '\n')
           lineCount ++;
        }//end forMessage was edited by:
    scottie_uk
    Message was edited by:
    scottie_uk

    Well, here is a C version. On my computer the Java version (reply 9 above) is slightly faster than C. YMMV. For stuff like this a compiler can be hard to beat even with assembler, as you need to do manual loop unrolling and method inlining which turn assembly into a maintenance nightmare.
    // gcc -O6 -fomit-frame-pointer -funroll-loops -finline -o newlines.exe newlines.c
    #include <stdio.h>
    #include <string.h>
    #if defined(__GNUC__) || defined(__unix__)
    #include <time.h>
    #include <sys/time.h>
    #else
    #include <windows.h>
    #endif
    #if defined(__GNUC__) || defined(__unix__)
    typedef struct timeval TIMESTAMP;
    void currentTime(struct timeval *time)
        gettimeofday(time, NULL);
    int milliseconds(struct timeval *start, struct timeval *end)
        int usec = (end->tv_sec - start->tv_sec) * 1000000 +
         end->tv_usec - start->tv_usec;
        return (usec + 500) / 1000;
    #else
    typedef FILETIME TIMESTAMP;
    void currentTime(FILETIME *time)
        GetSystemTimeAsFileTime(time);
    int milliseconds(FILETIME *start, FILETIME *end)
        int usec = (end->dwHighDateTime - start->dwHighDateTime) * 1000000L +
         end->dwLowDateTime - start->dwLowDateTime;
        return (usec + 500) / 1000;
    #endif
    static int count(register char *txt)
        register int count = 0;
        register int c;
        while (c = *txt++)
         if (c == '\n')
             count++;
        return count;
    static void doit(char *str)
        TIMESTAMP start, end;
        long time;
        register int n;
        int total = 0;
        currentTime(&start);
        for (n = 0; n < 1000000; n++)
         total += count(str);
        currentTime(&end);
        time = milliseconds(&start, &end);
        total *= 4;
        printf("time %ld, total %d\n", time, total);
        fflush(stdout);
    int main(int argc, char **argv)
        char buf[1024];
        int n;
        for (n = 0; n < 256 / 4; n++)
         strcat(buf, "abc\n");
        for (n = 0; n < 5; n++)
         doit(buf);
    }

  • Which method to count the number of character in a string?

    Hi all,
    I want to know which class and method to count the number of character in a string?
    Gary

    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html

  • Getting count of occurances of a string in a column value

    Hi,
    Is there a way to get the number of occurences of a string in a single column value?
    Example:
    CREATE TABLE STRING_CNT(X VARCHAR2(100));
    INSERT INTO STRING_CNT(X) VALUES('OracleXXOracleXXOracleXXOracle');
    Commit;
    Now the string 'Oracle' is repeated 4 times in the inserted value. I would like to get this count using SQL.Can some one tell me how to get this?
    I was asked this interesting question in an interview today.

    hi<br>
    u can get the occurrence of a string in text as
    follow<br>
    >
    SELECT (LENGTH(x)-LENGTH(REPLACE(x,'Oracle', ' ' )))<br>
    / LENGTH('Oracle') as<br>
    Occurrence FROM STRING_CNT;<br><br>
    <br>
    Are you sure...?<br>
    <br>
    <br>
    SQL> with STRING_CNT as
      2  (select '1.Oracle2.Oracle3.' x
      3  from dual)
      4  SELECT (LENGTH(x)-LENGTH(REPLACE(x,'Oracle', ' ' ))) / LENGTH('Oracle') as Occurrence
      5  FROM STRING_CNT;
    OCCURRENCE
    1.66666667
    <br>
    Sidenote: Please give a try before posting..<br>
    And you are posting a wrong solution after a TESTED right solution posted hours before..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Getting count of occurances of a string in a within a string

    Dear all,
    I want to find how many times the particular number 11 is present in the string ',11,12,13,14,11,16,17,11,23,11,'.
    expected answer 3.
    Please help me to write the sql statement.
    SQL> select length(regexp_replace(',11,12,13,12,11,', '[^11]')) / length('11') cnt from dual;
           CNT
           3.5
    tried the above one but no luck.
    Regards
    Rajat

    regexp_count ... But I see 4 11's .. Did I miss anything?
    SELECT REGEXP_COUNT (',11,12,13,14,11,16,17,11,23,11,', ',11,') FROM DUAL;
    Cheers,
    Manik.

Maybe you are looking for

  • Can't authenticate Mac VPN client from RADIUS server

    Hello, I'm a real noob here so please bear with me. I have been able to configure my PIX 515E to allow VPN connections onto my network, but what I need to do is set up some sort of user authentication to control access at a user level. From what I've

  • How do I get a webpage to print in a larger font?

    When I increase the size of the font in internet options, it helps the printed page, but increases the size of the webpage so much it is way too large. How can I increase just the size of my printed page?

  • Inserting rows into a table

    Hi, I want to insert values into a table 'Reasons'. The table 'Reason' has 5 columns out of 5 two columns has static data say column A value 'A' column E value sysdate But in the other three columns the vlues are repeating and as follows. Column B al

  • Setting default value in dynamic parameter

    Post Author: gazala CA Forum: General I have a dynamic parameter which is also displaying All static value as first item in th list.I want to make ALL as default in the parameter but its giving problem.Problem is when i set ALL as default it doesn't

  • How to reverse/change SRM PO with status "transaction completed"

    We use Extended Classic scenario in our company.      There is a PO has outstanding G/R balance,   but user accidently hit the button "complete"on this PO  in SRM ,   in result the PO has been completed with status "transaction completed".    And not