zoukankan      html  css  js  c++  java
  • 在字符串里寻找某字符出现的个数

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 字符串1
    {
        class Program
        {
            static void Main(string[] args) 
            {
                int n = 0; 
    
                Console.WriteLine("请输入字符串:"); 
    
                string B = Console.ReadLine();     
    
                B = B.ToLower();   
                  
                if (B.IndexOf("b") < 0)       
                {
                    Console.WriteLine("您输入的字符串里不包含字母b");
    
                }
                else
                {
    
                    int c = B.Length;
    
                    for ( n = 0; n <= c; n++)
                    {
                        int b = B.IndexOf("b");
                        if (b < 0)
                                              
                            break;             
           
                        B = B.Substring(b+1);
    
                    } Console.WriteLine("字符串中含b有" +n+"个");
                    
                }Console.ReadLine();
                
    
            }
        }
    }
    

      

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 作业4
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("请输入字符串:");
    
                string A = Console.ReadLine();
                A = A.ToLower();
    
                if (A.IndexOf("b") < 0)
                {
                    Console.WriteLine("您输入的字符串里不包含b");
                }
                else
                {
                    int C = A.Length;
    
                    A = A.Replace("b", "");
    
                    int Q = A.Length;
    
                    int w = C - Q;
                    Console.WriteLine("您输入的字符串中有"+w+"个b");
    
    
                } Console.ReadLine();
            }
        }
    }
    

      把b替换成无字符    俩长度相减

  • 相关阅读:
    JSONObject登录接口
    HttpClient跨域请求post
    线段树个人理解及模板
    Python基本语法(一)
    Boyer-Moore算法
    Sunday算法浅谈
    Kmp算法浅谈
    bm坏字符 , Horspool算法 以及Sunday算法的不同
    字典树的建立和基本查找
    CF Round551 Div2 题解
  • 原文地址:https://www.cnblogs.com/hanke123/p/4709357.html
Copyright © 2011-2022 走看看