BaseSplitter.cs
资源名称:2.rar [点击查看]
上传用户:hshongkong
上传日期:2021-11-20
资源大小:10241k
文件大小:2k
源码类别:
多国语言处理
开发平台:
C#
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.IO;
- namespace ChineseSplitter
- {
- /// <summary>
- /// 中文切割基类
- /// </summary>
- public abstract class BaseSplitter
- {
- /// <summary>
- /// 切割字符串
- /// </summary>
- /// <param name="inputStr">待切割字符串</param>
- /// <returns>切割结果</returns>
- public abstract string Split(string inputStr);
- /// <summary>
- /// 切割文件
- /// </summary>
- /// <param name="textPath">文件路径</param>
- /// <returns>切割结果</returns>
- public string Split(FileInfo textPath)
- {
- return Split(textPath , Encoding.Default);
- }
- /// <summary>
- /// 切割文件
- /// </summary>
- /// <param name="textPath">文件路径</param>
- /// <param name="textEncoding">文件编码</param>
- /// <returns>切割结果</returns>
- public string Split(FileInfo textPath, Encoding textEncoding)
- {
- string fileText = "";
- try
- {
- FileStream myStream = textPath.Open(FileMode.Open);
- StreamReader myReader = new StreamReader(myStream, textEncoding);
- fileText = myReader.ReadToEnd();
- }
- catch (Exception ex)
- {
- throw ex;
- }
- return Split(fileText);
- }
- /// <summary>
- /// 释放内存
- /// </summary>
- public abstract void Dispose();
- }
- }