zoukankan      html  css  js  c++  java
  • 关于字符串操作的一些常用户到的一些基本东西..

    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 "错误";
            }
        }
    }

  • 相关阅读:
    解决行内块元素(inline-block)之间的空格或空白问题
    gzip压缩文件&webPack配置Compression-webpack-plugin
    IOS微信禁用分享跳转页面返回BUG修复
    开发自己的composer包
    深入理解Java中的迭代器
    理解JDK1.5的自动装箱拆箱
    [design-patterns]设计模式之一策略模式
    [java]final关键字的几种用法
    [java]static关键字的四种用法
    [java]我的数据在哪里?——数据的内存模型
  • 原文地址:https://www.cnblogs.com/yzenet/p/2387612.html
Copyright © 2011-2022 走看看