String.Split VS.正则表达式.拆分? [英] String.Split VS. Regex.Split?

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

问题描述

如果我有一个带基本分隔符的分隔文本文件(例如 |),我使用 String 还是 Regex 会有所不同吗 拆分?

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 如果您有 escaped 不想拆分的分隔符 (|例如).

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.SplitString.Split 是否还有其他原因?

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

推荐答案

Regex.Split 功能更强大,但对于具有基本定界(使用字符串中其他任何地方都不存在的字符)的安排,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.

就性能而言,您必须创建一个测试并尝试一下.但是,不要预先优化,除非您知道此功能将成为某些基本流程的瓶颈.

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.正则表达式.拆分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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