static void Main(string[] args) { string name = "今年春晚是录播?"; Convert(name); Console.ReadKey(); } static void Convert(string text) { for (int i = 0; i < text.Length ; i++) { for (int j = 1; j < text.Length + 1 - i; j++) Console.WriteLine(text.Substring(i, j)); } }
aspwebchh(aspwebchh)大爱正则嘛。
static List<string> SubName(string name) { List<string> result = new List<string>(); for (int i = 0; i < name.Length; i++) for (int j = 1; j < name.Length - i + 1; j++) result.Add(name.Substring(i, j)); return result; }
for (var i = 0; i < name.Length; i++) for (var len = 1; len < name.Length - i + 1; len++) sublist.Add(name.Substring(i, len));不过,我建议你不要直接使用ArrayList类型。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections;namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string s = "今年春晚是录播?"; ArrayList sublist = new ArrayList(); int j,k= s.Length; for (int i = 0; i <s.Length ; i++) { for (j = 1; j <= k ; j++) { sublist.Add(s.Substring(i, j).ToString()); } k--; } for (int u = 0; u < sublist.Count; u++) { Console.WriteLine(sublist[u]); } } } }
string name = "今年春晚是录播?";
for (int i = 0; i < name.Length; i++)
{
for (int j = 0; j < name.Length - i; j++)
{
string regex = @".{" + (j + 1) + "}";
Regex regexp = new Regex(regex);
Match match = regexp.Match(name, i, name.Length - i);
list.Add(match.Value);
} } for (int i = 0; i < list.Count; i++)
{
Response.Write(list[i].ToString() + "<br/>");
}
int i = 0;
char[] arr = name.ToCharArray();
while(i<arr.Length )
{
for (int j = 0; j < arr.Length - i; j++)
{
string regex = @".{" + (j + 1) + "}";
Regex regexp = new Regex(regex);
Match match = regexp.Match(name, i, name.Length - i);
Console.Write(match.Value + "\n");
}
i++;
}
今
今年
今年春
今年春晚
今年春晚是
今年春晚是录
今年春晚是录播
今年春晚是录播?
年
年春
年春晚
年春晚是
年春晚是录
年春晚是录播
年春晚是录播?
春
春晚
春晚是
春晚是录
春晚是录播
春晚是录播?
晚
晚是
晚是录
晚是录播
晚是录播?
是
是录
是录播
是录播?
录
录播
录播?
播
播?
?
{
string name = "今年春晚是录播?";
Convert(name);
Console.ReadKey();
} static void Convert(string text)
{
for (int i = 0; i < text.Length ; i++)
{
for (int j = 1; j < text.Length + 1 - i; j++)
Console.WriteLine(text.Substring(i, j));
}
}
{
List<string> result = new List<string>();
for (int i = 0; i < name.Length; i++)
for (int j = 1; j < name.Length - i + 1; j++)
result.Add(name.Substring(i, j));
return result;
}
for (var len = 1; len < name.Length - i + 1; len++)
sublist.Add(name.Substring(i, len));不过,我建议你不要直接使用ArrayList类型。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s = "今年春晚是录播?";
ArrayList sublist = new ArrayList();
int j,k= s.Length;
for (int i = 0; i <s.Length ; i++)
{
for (j = 1; j <= k ; j++)
{
sublist.Add(s.Substring(i, j).ToString());
}
k--;
}
for (int u = 0; u < sublist.Count; u++)
{
Console.WriteLine(sublist[u]);
}
}
}
}