Does any one know of a faster method to do String.Split()?

后端 未结 14 1166
傲寒
傲寒 2020-12-03 10:57

I am reading each line of a CSV file and need to get the individual values in each column. So right now I am just using:

values = line.Split(delimiter);
         


        
14条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 11:21

    You can assume that String.Split will be close to optimal; i.e. it could be quite hard to improve on it. By far the easier solution is to check whether you need to split the string at all. It's quite likely that you'll be using the individual strings directly. If you define a StringShim class (reference to String, begin & end index) you'll be able to split a String into a set of shims instead. These will have a small, fixed size, and will not cause string data copies.

提交回复
热议问题