C#: 文件的读写操作

前言:
在Unity项目中,涉及文件的读写操作,还是比较常见的。所以有必要学习一下,IO流的操作。下面以 检测 游戏中的用户昵称是否含有敏感词汇 为例,进行具体实践操作。

如图,在Unity 编辑器中生成一个 文件读写工具,用来检测词库冲突问题。
Check_word

代码实现:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Data;
using UnityEditor;

public class CheckStrifeWord : EditorWindow
{
    private string m_nickPath = "/Text/test.txt";
    private string m_fobidPath = "/Text/words.txt";
    private string[] m_nickArray = null;
    private string[] m_forbidArray = null;
    private string[] m_tempArray = null;

    string[] m_newArray = null;
    private List<string> list = new List<string>();
    List<string> m_testList = new List<string>();
    string str = "";


    // 添加 到Tool 菜单栏 : EditorWindow 
    [MenuItem("Tools/Check word")]

    static public void OpenBMFontMaker()
    {
        EditorWindow.GetWindow<CheckStrifeWord>(false, "Check Word", true).Show();
    }

    private void OnGUI()
    {
        if (GUILayout.Button("词库检测"))
        {
            Debug.Log("\n==== 词库检测 =====");
            Init(0);
        }
        if (GUILayout.Button("提取 昵称词库 重复字段"))
        {
            Debug.Log("\n==== 提取 昵称词库 重复字段 =====");
            m_newArray = new string[0];
            Debug.Log("\n==== 新字符串长度 =====" + m_newArray.Length);
            Init(1);
        }
        if (GUILayout.Button("提取 敏感词库 重复字段"))
        {
            Debug.Log("\n==== 提取 敏感词库 重复字段 =====");
            Init(2);
        }
        if (GUILayout.Button("提取 昵称词库 冲突敏感词组"))
        {
            Debug.Log("\n==== 提取 昵称词库 冲突敏感词组 =====");
            Init(3
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值