c# - 拆分字符串错误 : cannot convert from string to char

标签 c# unity3d

我有以下代码:

textPath = Application.streamingAssetsPath + "JSONFiles/text_to_text.txt";
 StreamReader reader = new StreamReader(textPath);
 string text = reader.ReadLine();
 string[] colour = text.Split(",");
 m_textMeshPro.SetText(text);
 reader.Close();

代码正在从 txt 文件中读取一行。我在统一中使用它。但是,当我将鼠标悬停在它上面时,拆分函数 (",") 中的参数下方有一条红线。它说“参数 1:无法从‘字符串’转换为‘字符’。

最佳答案

使用这个,用单引号替换双引号来指定一个字符。

string[] colour = text.Split(',');

关于c# - 拆分字符串错误 : cannot convert from string to char,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54503151/

相关文章:

unity3d - 我无法在 unity hub 中激活许可证

C# - 在给定起始工作日的情况下,获取一个月中的周列表的最佳方法是什么?

c# - 数据验证在编辑模式下不起作用

C# 显示数据库的 2 列,共有 28 列

c# - 是否组合了不同的 IQueryable 对象?

c# - 如何统一禁用物理系统

c# - C#表单: How to show a form when initalization takes a long time?

c# - Unity 4.3 - 2D,如何以编程方式将 Sprite 分配给对象

c# - 在主线程中获取 UdpClient 接收数据

c# - 开发人员如何引用大量不同的实体预制件?