String.Split() Function mysteriously ignoring duplicates

前端 未结 2 1988
你的背包
你的背包 2020-12-07 06:27

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

However it seems that ALL duplicates are removed automatically!

           


        
相关标签:
2条回答
  • 2020-12-07 07:17

    Even though split shouldn't remove duplicates (tested here) you could try using Regex and Linq.

    var words = Regex.Matches("Node,Node2,Node2,Lamp,Lamp,Node1,Node3,Node4", @",?(\w+)").Cast<Match>().Select(x => x.Groups[1].Value);
    
    0 讨论(0)
  • 2020-12-07 07:22

    This is an infamous gotchya in Unity:

    very simply, in the Unity console:

    IT DOES NOT PRINT DUPLICATES!!!

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

    It's that simple.

    0 讨论(0)
提交回复
热议问题