你怎么分割字符串在C#中的字符串 [英] how do you split a string with a string in C#

查看:98
本文介绍了你怎么分割字符串在C#中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个字符串分割成一个String作为分隔符的String []。

I would like to split a string into a String[] using a String as a delimiter.

String delimit = "[break]";
String[] tokens = myString.Split(delimit);

但是,只有上面的方法适用于一个字符作为分隔符。

But the method above only works with a char as a delimiter.

任何考生?

推荐答案

这样的:

mystring.Split(new string[] { delimit }, StringSplitOptions.None);

由于某些原因, 拆分<唯一的过载/ code> 是一个字符串把它作为一个数组,伴随着 StringSplitOptions 。结果
我不知道为什么没有一个 string.Split(PARAMS字符串[])超载。

For some reason, the only overloads of Split that take a string take it as an array, along with a StringSplitOptions.
I have no idea why there isn't a string.Split(params string[]) overload.

这篇关于你怎么分割字符串在C#中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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