zoukankan      html  css  js  c++  java
  • 获得字符串的某些词

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 字符串练习
    {
        class Program
        {
            static void Main(string[] args)
            {
                
                t2();
    
    
            }
    
    
            #region t1 //
    
    
            public static void t1()
            {
                Console.WriteLine("输入一个字符串,马上就给你反转过来");
                string input = Console.ReadLine();
                string[] wds = input.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < wds.Length; i++)
                {
                    wds[i] = ResStr(wds[i]);
    
                }
                string rs = string.Join(" ", wds);
                Console.WriteLine(rs);
                Console.ReadKey();
            }
            #endregion
    
    public static void t2()
    {
        string str = "今天是201年34月34日";
        int yearIndex = str.IndexOf("");//字符串从0开始计数,yearIndex为6
        int getStartIndex = GetStart(str, yearIndex);
        int mouthIndex = str.IndexOf("");
        int dayIndex = str.IndexOf("");
        string yStr = str.Substring(getStartIndex+1, yearIndex-getStartIndex-1);
        string mStr = str.Substring(yearIndex+1, mouthIndex - yearIndex - 1);
        string dStr = str.Substring(mouthIndex+1, dayIndex - mouthIndex - 1);
        Console.WriteLine(yStr);
        Console.WriteLine(mStr);
       Console.WriteLine(dStr);
        Console.ReadKey();
    }

     public static void t3()//读出csv文件内容
            {
                string[] str = File.ReadAllLines("t.csv",Encoding.Default);
                for (int i = 0; i < str.Length; i++)
                {
                    string[] juti = str[i].Split(',');
                    Console.WriteLine("姓名{0};电话{1}",juti);//标准流,所以不需要使用juti[0],juti[1]这样的形式
                   
                }
                Console.ReadKey();
            }
    private static string ResStr(string input) { char[] wd = input.ToCharArray(); for (int i = 0; i < wd.Length/2; i++) { char temp = wd[i]; wd[i] = wd[wd.Length - i-1]; wd[wd.Length - i - 1] = temp; } return new string(wd); } //获得起始位置下标 private static int GetStart(string str,int yearIndex) { for (int i = yearIndex; i >=0; i--) { if (!char.IsDigit(str[i]))//判断是否为十进制数 { return i; } } return -1; } } }
  • 相关阅读:
    解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.xyfer.dao.UserDao.findById
    Oracle使用MyBatis中RowBounds实现分页查询
    普元EOS开发经验总结——不定期持续更新中
    Vue数据列表倒计时展示
    Java后端学习路线
    Linux下命令行安装WebLogic 10.3.6
    Oracle快速运行一指禅
    maven学习知识点汇总
    EOS下控制台以及图形界面打印sql语句
    Myeclipse使用过程配置汇总
  • 原文地址:https://www.cnblogs.com/hcrs/p/4510955.html
Copyright © 2011-2022 走看看