根据子字符串分割字符串 [英] split a string based on substring
本文介绍了根据子字符串分割字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
每当用户输入字符串时,我都会在该字符串后附加另一个字符串以进行分割,现在我必须根据该字符串进行检索,如何根据该字符串对其进行分割?
我要用于拆分的字符串是〜^ @"
例如:这是一个示例字符串〜^ @今天已添加.
Hi all,
when ever user enters string i will append another string to it for splitting purpose,now i have to retrieve based on that string,how do i split it based on that?
the string i want to use for splitting is "~^@"
eg:this is an example string~^@today it has been added.
Regex regex = new Regex(@"\b~^@\b");
string[] substrings = regex.Split("this is an example string~^@today it has been added");
我尝试使用它,但没有用.
在此先感谢,
i tried using this but it did not work.
thanks in advance,
推荐答案
您为什么不使用此
why don''t you use this
"this is an example string~^@today it has been added".Split(new string[]{"~^@"},StringSplitOptions.None)
嗨
您可以尝试以下解决方案
hi
you can try below solution
string str = "this is ~!@ this is 1 ~!@ this is 2 ~!@ this is 4";
string[] saprator ={"~!@"};
String[] strSplit= str.Split(saprator,StringSplitOptions.RemoveEmptyEntries);
字符串[] yourstring =字符串
yourstring.substring(分隔的文本或字符);
您将以稀疏的形式得到它
string []yourstring=the string
yourstring.substring(seperating Text or character);
Your will get it in arrary form check it
这篇关于根据子字符串分割字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文