C # Classic Pen question-get the same word utilises and its number in a string

Source: Internet
Author: User
This article from: http://www.cnblogs.com/kejie/p/5971773.html

Public dictionary<char,int> Getstrsameas (String str)
{
Converts a string into an array of characters. Char[] Chararray=str. ToCharArray ();
Defines a dictionary with key keys as the number of characters to be taken out, and value as the corresponding character. Dictionary<char,int> dic=new dictionary<char,int> ();
for (int i=0;i<chararray.length;i++) {
If the current dictionary does not have this character, add a new one, or increment the corresponding value of the current character by one. if (!dic. ContainsKey (Chararray[i])) { dic. ADD (chararray[i],1); } else { dic[chararray[i]]=dic[chararray[i]]++; } }
return DIC;}

C # Classic Pen question-get the same word utilises and its number in a string

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.