110,534
社区成员
发帖
与我相关
我的任务
分享
string str="IBM发布基于人脑特性设计的全新计算架构和编程语言";
var result=str.ToCharArray().Select((x,i)=>new {x,i}).GroupBy(x=>x.i/5).Select(g=>new string(g.Select(s=>s.x).ToArray()));
string str="IBM发布基于人脑特性设计的全新计算架构和编程语言";
var result=str.ToCharArray().GroupBy(x=>str.IndexOf(x)/5).Select(x=>new string(x.ToArray()));
string[] result=Regex.Split(yourstr,"(?<=\\G.{5})");
具体可参考我的blog: http://blog.csdn.net/q107770540/article/details/6436973
using System;
public class SubStringTest
{
public static void Main()
{
string[] info = { "Name: Felica Walker", "Title: Mz.", "Age: 47", "Location: Paris", "Gender: F" };
int found = 0;
Console.WriteLine("The initial values in the array are:");
foreach (string s in info)
Console.WriteLine(s);
Console.WriteLine("{0}We want to retrieve only the key information. That is:", Environment.NewLine);
foreach (string s in info)
{
found = s.IndexOf(":");
Console.WriteLine(s.Substring(found + 1).Trim());
}
}
}
另外我把正则的例子也给你个
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System.Text.RegularExpressions;
namespace cop
{
class HelloWorld
{
public static void Main(String[] args)
{
string test = "123abc";
Regex reg = new Regex(@"[a-z]", RegexOptions.IgnoreCase);
string str = "";
MatchCollection mc = reg.Matches(test);
foreach (Match m in mc)
{
str += m.Value + "\n";
}
Console.WriteLine(str);
/*
*输出结果 a b c
*/
Console.ReadKey();
}
}
}
var value = Regex.Matches("IBM发布基于人脑特性设计的全新计算架构和编程语言", @"\w{5}");