我怎么可以拆分使用字符串分隔符的字符串? [英] How can I split a string with a string delimiter?

查看:169
本文介绍了我怎么可以拆分使用字符串分隔符的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/1126915/how-do-i-split-a-string-by-a-multi-character-delimiter-in-c\">How我在C#中的多字符分隔符分割字符串?


我有这个字符串:

 我的名字是马可和我来自意大利

我想拆呢,用分隔符是Marco和,所以我应该得到与

数组

  • 我的名字在[0]和

  • 我来自意大利在[1]。

我如何用C#做呢?

有试过

  .Split(是马可和)

但希望只有一个字符。


解决方案

 的String []标记= str.Split(新[] {是Marco和},StringSplitOptions.None) ;

如果你有一个字符分隔符(例如像),可以减少到

 的String []标记= str.Split('');

Possible Duplicate:
How do I split a string by a multi-character delimiter in C#?

I have this string :

My name is Marco and I'm from Italy

I'd like to split it, with delimiter is Marco and, so I should get an array with

  • My name at [0] and
  • I'm from Italy at [1].

How can I do it with C#?

Tried with

.Split("is Marco and")

but it wants only a single char.

解决方案

string[] tokens = str.Split(new[] { "is Marco and" }, StringSplitOptions.None);

If you have a single character delimiter (like for instance ,), you can reduce that to

string[] tokens = str.Split(',');

这篇关于我怎么可以拆分使用字符串分隔符的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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