String.Split() 函数神秘地忽略重复项 [英] String.Split() Function mysteriously ignoring duplicates

查看:37
本文介绍了String.Split() 函数神秘地忽略重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Unity3D 中,我正在读取一个文本文件,其中包含有关节点及其连接的信息.

In Unity3D I am reading a textfile with information on nodes and its connections.

但是似乎所有重复项都会自动删除!

However it seems that ALL duplicates are removed automatically!

           for (int j = 0; j < tokens.Length; j++)
           {
               Debug.Log(tokens[j]);
           } }

控制台结果:

Node,Node2,Node2,Lamp,Lamp,Node1,Node3,Node4   // string text
Node
Node2
Lamp
Node1
Node3
Node4

因此,在遍历数组时,它似乎跳过了重复项.

Thus it seems that it skips duplicates, when looping over the array.

推荐答案

这是一个Unity中臭名昭著的陷阱:

很简单,在 Unity 控制台中:

very simply, in the Unity console:

它不会打印复制品!!!

仔细查看控制台输出,有一个 Collapse 切换开关,可以显示或不显示重复项.

Look more carefully by the console output, and there's a Collapse toggle that makes it show or not show duplicates.

就这么简单.

这篇关于String.Split() 函数神秘地忽略重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆