问题 C: c#统计字符串中数字字符的个数

题目描述

假设有一个GetNumber方法(参数为字符串strSource),编写一个静态方法可以用来统计字符串strSource中数字字符的个数。

输入

输入一个字符串strSource

输出

strSource字符串中数字字符的个数

样例输入

.wrapper {position: relative;} #input {position: absolute;top: 0;left: 0;opacity: 0;z-index: -10;} copy

asffkl8asjkfjklas3jdf9lkj!

Made by hxl.

样例输出

3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 统计字符串中数字字符的个数
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int count = 0;
            for (int i = 0; i < s.Length; ++i)
            {
                if (s[i] >= ‘0‘ && s[i] <= ‘9‘)
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}

  

原文地址:https://www.cnblogs.com/mjn1/p/12576459.html

时间: 2024-08-13 02:48:51

问题 C: c#统计字符串中数字字符的个数的相关文章

统计字符串中汉字的个数

字符串可以包括数字.字母.汉字或者其他字符.使用Charater类的isDigit()方法可以判断字符串中的某个字符是否为数字, 使用Character类的isLetter()方法可以判断字符串中的某个字符是否为字母. 本案例将介绍用"正则表达式"来判断字符串中的某个字符是否为汉字,并统计该字符串中汉字的数量. 关键技术: Java中提供Pattern用于正则表达式的编译方式,该类的静态方法matches()可以执行正则表达式的匹配.该方法的声明如下: public static bo

统计字符串中单词的个数

1.单纯统计单词个数,单词与单词之间只考虑空格的情况 // word_statistic.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #include <string> using namespace std; #define M 10000 #define N 20 int _tmain(int argc, _TCHAR* argv[]) { char str1[M]={0};

关于统计字符串中重复字符个数

一般使用map集合的键不唯一来统计 map.containsKey(b)//判断map集合键中是否包含b 若果不包含就将b作为键存入集合中值为1 map.put(b,1); 如果键中包含那么键不变,值在原来的基础上加1 map.put(b,map.get(key)+1); 代码展现 for(Character key : keySet){ if(!map.contiansKey(b)){ map.put(b,1); }else{ map.put(b,map.get(key)+1); } }

统计字符串中大写字母个数

可将字符串转为字符数组,然后对数组进行遍历,进而统计大写字母的个数. 下面给出代码: import java.util.Scanner; public class Main { public static void main(String args[]){ Scanner in = new Scanner(System.in); String str = in.nextLine(); int count = 0; char ch[] = str.toCharArray(); //转为字符数组 f

正则表达式统计字符串中数字的个数

#coding=utf-8import stringimport restr='i have 300 yuan, you 234 234 give me 200 again, then i have 500 yuan'iList= re.findall(r"\d+",str)print "string:",strprint "total digit number:",len(iList) 原文地址:https://www.cnblogs.com/

技巧之C#统计字符串中字符出现的次数(转)

方法1.自定义类 class CharNum { private char c; private int num; public char C { get { return c; } } public int Num { get { return num; } set { num = value; } } public CharNum(char ch) { this.c = ch; this.num = 1; } } static void Main(string[] args) { /* */

c语言代码编程题汇总 :统计字符串中的大写和小写字母的个数

统计字符串中的大写和小写字母的个数 程序代码如下: 1 /* 2 2017年3月6日19:42:21 3 功能:统计字符串中的大写和小写字母的个数 4 */ 5 6 #include "stdio.h" 7 void fun (char *,int *,int *); 8 9 int main (void) 10 { 11 int m = 0,n = 0; 12 int *Pm = &m, *Pn = &n; 13 char s[100]; 14 printf (&qu

Java基础知识强化之集合框架笔记61:Map集合之统计字符串中每个字符出现的次数的案例

1. 首先我们看看统计字符串中每个字符出现的次数的案例图解:

字符串之“统计一个字符串中单词的个数”

题目:统计一个字符串中单词的个数 输入一行字符,统计其中有多少个单词,单词之间用空格分隔开 输入:my name is jacky 输出:the number of word is 4 代码如下: #include <stdio.h> int main(int argc, char *argv[]) { char str[80]; int i=0,num=0,flag=0; char c; gets(str); while((c=str[i])!='\0') { if(c==' ') flag