如何在asp.net中拆分替代字符串值 [英] how to split alternative string values in asp.net
本文介绍了如何在asp.net中拆分替代字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
string A="1234567890";
how to split string A to get below values??
string b=13579;
string c=24680;
推荐答案
为什么不简单地循环字符?类似
Why not simply loop the characters? Something like
string a="1234567890";
string b= "";
string c = "";
for (int counter = 0; counter < a.Length; counter++) {
if (counter % 2 == 0) {
b += a.ToArray()[counter];
} else {
c += a.ToArray()[counter];
}
}
当然最好使用stringbuilder并将原始字符串转换为数组一次,依此类推,但要获得这个想法...
Of course it would be better to use a stringbuilder and to convert the original string to an array only once and so on, but to get the idea...
一个简单的迭代可以完成这项工作:
A simple iteration could do the job:
static void mysplit(string input, out string even, out string odd)
{
even = odd = string.Empty;
for (int n = 0; n < input.Length; ++n)
{
if (n % 2 == 0)
even += input[n];
else
odd += input[n];
}
}
这篇关于如何在asp.net中拆分替代字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文