• 关于字符串操作的一些常用户到的一些基本东西..


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

    namespace string_传智博客园_
    {
        class Program
        {
            static void Main(string[] args)
            {
                #region 接受用户的输入字符串,反序输出"abc"->"cba"
                  //接受用户的输入字符串,反序输出"abc"->"cba"
                //string s = Console.ReadLine();
                //for (int i=s.Length-1;i >=0; i--)
                //{
                //    Console.Write(s[i]);
                //}
               
                //s[2]=c,s[1]=b,s[0]=a; 我们通过下标2到0不就输出对应的值?即反序输出
                #endregion

                #region 接受用户输入一句英文,将其中的单词反序输出。"hello c sharp"->"sharp c hello"
              //接受用户输入一句英文,将其中的单词反序输出。"hello c sharp"->"sharp c hello"
                //string sp = Console.ReadLine();
                //string[] words = sp.Split(' ');
                //for (int i = words.Length - 1; i >= 0;i-- )
                //{
                //    Console.Write(words[i]+" ");
                //}
                #endregion

                #region abc@qq.com 取出abc 和qq.com
              /*  //abc@qq.com 取出abc 和qq.com
                string email = Console.ReadLine();
                int atIndex = email.IndexOf('@');
                string usename = email.Substring(0, atIndex);
                string 域名 = email.Substring(atIndex+1);
                Console.WriteLine(usename);
                Console.WriteLine(域名);
               */
                #endregion

               #region ini格式文件
                string[] line = File.ReadAllLines(@"C:\Users\Administrator\Desktop\string(传智博客园)\string(传智博客园)\txt\sp.txt", Encoding.Default);
                foreach (string item in line)
                {
                    string[] strs = item.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    string title = strs[0];//标题
                    string author = strs[1];//作者

                    if (title.Length > 17)
                    {
                        title = title.Substring(0, Math.Min(17, title.Length));
                        title = title + "....";
                    }
                    else
                    {
                        title = title;
                    }

                    Console.WriteLine("{0}+++++{1}", title, author);
                }
                #endregion


            }
            static string GetString(string fileURL, string fileName)
            {
                string[] sp = File.ReadAllLines(fileURL, Encoding.Default);
                foreach (string item in sp)
                {
                    string[] sts = item.Split(new char[] { '=', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    string name = sts[0];
                    string value = sts[1];
                    if (name == fileName)//或者不要分割字符 直接 name.Trim()也可以;
                    {
                        return value.Trim();
                    }
                }
                return "错误";
            }
        }
    }

  • 相关阅读:
    LOJ164 高精度除法
    CQOI2013 新Nim游戏 和 BZOJ1299 巧克力棒
    UOJ514 通用测评号 和 CF891E Lust
    CF526F Pudding Monsters 和 CF997E Good Subsegments
    UOJ513 清扫银河
    SNOI2020 水池
    NOI2015 品酒大会 和 SNOI2020 字符串
    SNOI2020 生成树
    BJOI2020 封印
    UOJ523 半前缀计数
  • 原文地址:https://www.cnblogs.com/yzenet/p/2387612.html
Copyright © 2020-2023  润新知