Total members 11894 |It is currently Thu Nov 21, 2024 6:58 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Find occurrences of each character in a string
Given two strings s1 and s2 as parameters to your function, find out the number of
occurrences of each character of s2 in s1 and return a string which has the count(in s1) of
each character of s2 in order that the characters occur in s2. (Note: The function should be
case sensitive.)
Sample Run Input:
s1 = "RenaissaNce"
s2="aRaans"
Output:
"a2R1n1s2"





Author:

You will need to count the occurrences of a Character in a string ,
Code:

int FindOccurrences 
(String s,char mychar) {
  int count = 0;

  for (int i = 0; i < s.size(); i++)
    if (s[i] == mychar) count++;

  return count;
}
 


in java so
Code:
String string1="Value1";
        String string2="Value2";
        char x='a';
        int found=0;
        for(int i=0;i<string1.length();i++)
        {
            if(string1.charAt(i)==x){
                found++;
            }
       
        }


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : Find occurrences of each character in a string
 Number of Occurrences of characters in a string     -  
 find a string     -  
 How to find server IP, PORT using String     -  
 Character Operations     -  
 character recognition     -  
 Reading a Specific Character in php     -  
 ANSI code value of character     -  
 Sending One lakh character in ajax     -  
 Handle Key event-keyboard-Get typed Character and its code     -  
 character running automatically / jump /duck/ functions     -  



Topic Tags

Java Strings
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com