Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
351 views
in Technique[技术] by (71.8m points)

.net - 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?

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).

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...