C#

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            #region 一行一行读取
            //int counter = 1;
            //string line;
            //System.IO.StreamReader file = new System.IO.StreamReader(@"F:/WinForm/test/test/test/test.txt");
            //while ((line = file.ReadLine()) != null)
            //{
            //    System.Console.WriteLine(line);
            //    counter++;
            //}
            //file.Close();
            //System.Console.WriteLine("There were {0} lines:", counter);
            //System.Console.ReadLine();
            #endregion

            #region 字符去空格一行一行字符串
            //    string File_Name = @"F:/WinForm/test/test/test/test.txt";
            //    if (!File.Exists(File_Name))
            //    {
            //        Console.WriteLine("{0}   does   not   exist!", File_Name);
            //        return;
            //    }
            //    ArrayList ar = new ArrayList();
            //    ar = GetString(File_Name);
            //    for (int i = 0; i < ar.Count; i++)
            //    {
            //        Console.WriteLine(ar[1]);
            //        string c = ar[1].ToString().Replace(" ", "");//去字符串中的空格
            //        string b = ar[1].ToString().Trim();//TRIM()只能删除前后空格
            //        string a = ar[1].ToString().Trim().Substring(8);//取前面8个字符
            //        int first=ar[1].ToString().IndexOf("<");
            //        int last=ar[1].ToString().LastIndexOf(">");
            //        string str2=ar[1].ToString().Substring(first+1,last-first-1);
            //        Console.WriteLine("{0}",str2);
            //        Console.WriteLine(c);
            //        Console.WriteLine(ar[2]);
            //        Console.ReadLine();
            //    }
            //}
            //public static ArrayList GetString(string a)
            //{
            //    ArrayList arr = new ArrayList();
            //    StreamReader sr = new StreamReader((System.IO.Stream)File.OpenRead(a), System.Text.Encoding.Default);
            //    try
            //    {
            //        while (sr.Peek() != -1)
            //        {
            //            arr.Add(sr.ReadLine());
            //        }
            //    }
            //    catch (Exception e)
            //    {
            //        Console.WriteLine(e.Message);
            //    }
            //    return arr;

            //}
            #endregion
            #region
            //string str = "A silly sentence used for silly purposes.";
            //System.Console.WriteLine("'{0}'", str);

            //bool test1 = str.StartsWith("a silly");
            //System.Console.WriteLine("starts with 'a silly'? {0}", test1);

            //bool test2 = str.StartsWith("a silly", System.StringComparison.OrdinalIgnoreCase);
            //System.Console.WriteLine("starts with 'a silly'? {0} (ignoring case)", test2);

            //bool test3 = str.EndsWith(".");
            //System.Console.WriteLine("ends with '.'? {0}", test3);

            //int first = str.IndexOf("silly");
            //int last = str.LastIndexOf("silly");
            //string str2 = str.Substring(first, last - first);
            //System.Console.WriteLine("between two 'silly' words: '{0}'", str2);
            //Console.ReadLine();

            #endregion
            #region
            string filename = @"F:/WinForm/test/test/test/test.txt";
            if (System.IO.File.Exists(filename))
            {
                Stream s = new FileStream(@"F:/WinForm/test/test/test/test.txt", FileMode.Open);

                StreamReader sr = new StreamReader(s, Encoding.Default);
                string str = sr.ReadToEnd().ToString().Trim().Replace(" ", "");
                int first = str.IndexOf("<");
                int last = str.LastIndexOf(">");
                string str1 = str.Substring(first, last - first);
                Console.WriteLine(str1);
                Console.ReadLine();
                sr.Close();
                s.Close();
            }
            #endregion
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值