函数神秘地忽略重复项

函数神秘地忽略重复项

本文介绍了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中的一个臭名昭著的怪癖:

This is an infamous gotchya in Unity:

非常简单,在Unity控制台中:

very simply, in the Unity console:

它不会重复打印!

IT DOES NOT PRINT DUPLICATES!!!

请更仔细地查看控制台输出,并且有一个Collapse开关,它可以显示或不显示重复项.

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

就这么简单.

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

07-27 21:10