问题描述
大家好,
我改用了regex方法,很好地回答了以下问题.
字符串输入="MKWVTFISLLLLFSSAYSRGVFRRDTHKSEIAHRFKDLGEEHFKGLVLIAFSQYLQVK"
另一个问题:
如果我想跳过分隔符时说每3个而不是每次到达分隔符时该怎么办?
这样说
一个小姐"将显示为
MKMVTFISLLLLFSSAYSR
GVFR
R
DTHKSEIAHR等
如何使用使用多个分隔符的分割字符串方法,但保留分隔符?
例如:
Hi all,
I got a great answer the question below using the regex method instead.
string input = "MKWVTFISLLLLFSSAYSRGVFRRDTHKSEIAHRFKDLGEEHFKGLVLIAFSQYLQVK"
Another question:
What if I wanted to skip splitting at a delimiter say every 3rd instead of every time it reaches the delimiter?
so say
"one miss" would read
MKMVTFISLLLLFSSAYSR
GVFR
R
DTHKSEIAHR etc
How would I use the split string method using multiple delimeters but keep the delimeters?
Ex:
string input = "MKWVTFISLLLLFSSAYSRGVFRRDTHKSEIAHRFKDLGEEHFKGLVLIAFSQYLQVK";
string[] words = newString.Split(''R'',''K'');
for (int i = 0; i <; words.Length - 1; i++)
{
sw.WriteLine(words[i]);
char[] sumLine = words[i].ToCharArray();
}
我想读
MK
WVTFISLLLLFSSAYSR
GVFR
R
DTHK
SEIAHR等
基本上在K或R上分割字符串,但在对序列写行时保留K或R
[edit]已添加代码块-OriginalGriff [/edit]
I want it to read
MK
WVTFISLLLLFSSAYSR
GVFR
R
DTHK
SEIAHR etc etc
basically split the string on K or R but keep the K or R when I writeline the sequence
[edit]Code block added - OriginalGriff[/edit]
推荐答案
string input = "MKWVTFISLLLLFSSAYSRGVFRRDTHKSEIAHRFKDLGEEHFKGLVLIAFSQYLQVK";
Regex regex = new Regex("([^KR])*[KR]");
MatchCollection ms = regex.Matches(input);
foreach (Match m in ms)
{
Console.WriteLine(m.Value);
}
这篇关于分割字符串,但保留多个定界符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!