String.Split VS. Regex.Split? [英] String.Split VS. Regex.Split?

查看:167
本文介绍了String.Split VS. Regex.Split?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个基本的分隔符分隔的文本文件(比如 | 为例)它有所作为我是否使用字符串正则表达式分裂?

If I have a delimited text file with a basic delimiter (say | for instance) does it make a difference whether I use a String or a Regex split?

我会看到一个与其它任何的性能提升?

Would I see any performance gains with one versus the other?

我假设你想使用 Regex.Split 如果你有逃脱分隔符,你不想拆就( \ | 为例)。

I am assuming you would want to use Regex.Split if you have escaped delimiters that you don't want to split on (\| for example).

还有没有其他的理由来使用 Regex.Split VS String.Split

Are there any other reasons to use Regex.Split vs String.Split?

推荐答案

Regex.Split能力更强,但对于基本delimitting安排(使用将不存在任何其他地方的字符串中的字符),该String.Split功能是非常容易的工作。

Regex.Split is more capable, but for an arrangement with basic delimitting (using a character that will not exist anywhere else in the string), the String.Split function is much easier to work with.

至于性能的话,你就必须创建一个测试和尝试。但是,不要pre-优化,除非你的知道的,这个功能将是一些必要的流程中的瓶颈。

As far as performance goes, you would have to create a test and try it out. But, don't pre-optimize, unless you know that this function will be the bottleneck for some essential process.

这篇关于String.Split VS. Regex.Split?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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